The Service Call control is used to invoke an AJAX service which can be called On Load, or programmatically.
Like almost all SPARK controls, you can trigger events that are fired when the user interacts with the control (see the Event and Methods sections below and the Event Handling article for more information). The user does not really interact with the Service Call control, the events are fired when the user gets a result or error from the AJAX call.
This control is most commonly used along with two variables; one as the input data for the AJAX Service, and the other as the results. This control allows for the option of an input value, which would be passed into the AJAX service and can be used there. The input value can be of any type and may be a list. Other functions include returning results from a database/SQL calls among many other things. The input variable can be bound to another control to allow the user to enter the data manually. The Service Call control does not need to be bound for it to work.
Input Value Formula Formula for input value of the service call control
Attached AJAX Service The AJAX service to run when this control is executed
Input Value Optional value used as input of the AJAX service. Changes to this value cause an automatic invocation of the AJAX service with the updated input - only if the Auto Run configuration option is checked.
Auto Run Option Run on start and whenever input data changes
Busy Indicator Busy icon to show while the service call is executing; None, Spinner, Refresh, Cog
These are the configuration option settings...
There are two variables, data (which is bound to the Input Value option of the Name Text control) and results (which is bound to the Service Call control in the behavior section in the General tab and is bound to the Output Value option of the Result Text control). If you want to pass in more than one object or value, you need to use a complex type for the input value. Remember to leave the input of your Ajax service named 'data' but change the type of data to the object you map to the Input Value configuration object! Also, make sure to leave the output of your Ajax service named 'results', you can leave the data object of ANY, unless you'd like to specify what the output will be (e.g. Decimal).
This control allows for AJAX invocation easily without having to use boundary events; AJAX logic can be called inside a Coach Page (heritage or client side) or inside a Coach View just as easily.
An AJAX Service is used to input the data and return a result. A Server Script was added to the AJAX service with the following code:
Line 1 adds a delay which allows the cog Busy Indicator to display (this delay is for demo purposes only, so one can observe the spinning/busy indicator). The rest of the script checks if there is data being inputted into the service, then returns a result of "Hello " along with the data that was entered.
This is the result before inputting data...
The cog spins while the service is executing
And after data has been inputted...
With the Service Call, there are 4 types of event handlers:
- On Load When the page loads
- On Invoked When the service call is executed
- On Results When the service call returns with results
- On Error When the service call returns with an error
For detailed information on the available methods for this control, access the JS Doc file.
- Author: Erick Quintanilla
- Date Created: June 8, 2015
- Date Modified: January 26, 2016