Working with Services - Updating form content after the user clicks submit
Have you ever wanted to update the form with some programmatic content after the user clicks submit but before the form gets submitted? You're in luck there is a way!
In this example we want to assign the form a unique ID right at the time the user submits the form. Using the validateButtonPressed event we can cancel the submit event, perform our asynchronous service call to get our next form ID and then programmatically submit the form.
1. In the validateButtonPressed event
//check the global variable that indicates a submission is allowed - this gets set by our service listener once the ID has been retrieved if(app.getSharedData().submitAllowed) { app.getSharedData().submitAllowed = false; //we have to reset the global variable for subsequent submissions within the same browser session return true; } else { //We get here the first time the user clicks submit. We call the async service and return false which cancels the submit event form.getServiceConfiguration('SC_ServiceConfig1').callService(); return false; }
In the form onLoad event place a listener for the service that is getting your ID:
//this gets called when the service is complete var srv = form.getServiceConfiguration('SC_ServiceConfig1'); srv.connectEvent("onCallFinished", function(success) { if(success) { //set the global flag to true so that when we programmatically trigger the submit it is allowed to proceed app.getSharedData().submitAllowed = true; // set ID to next number BO.F_SingleLine0.setValue(parseFloat(BO.F_Number.getValue()) + 1); //trigger the submit button var actionButtons = form.getStageActions(); for(var i=0; i<actionButtons.length; i++){ if(get(actionButtons, i).getId() === 'S_Submit') get(actionButtons, i).activate(); } });