hub.eb?material_id=120&track_id=394

Asynchronous server-side calls


When a function is executed asynchronously (opposed to synchronously), the application user does not have to wait for the execution to complete before continuing other tasks on the browser page. 

You can also execute a server-side function from the browser asynchronously by calling $eb.executeFunctionAsynchronously(successCallback, failureCallback, "myFunction").

  • successCallback: a function that will be called if the server-side function executes succesfully
  • failureCallback: a function that will be called if the server-side function cannot be executed

The following optional arguments can also be specified:

  • parameter: a parameter to pass to the function being executed.
  • autorefresh: instructs the AJAX mechanism to refresh the page with any changes made by the executed function
  • fullSubmit: validates and updates any field values on the page to the fields on the form before the server-side function is executed

Steps


1

Create a new form called myClientApi2 and make the page a Vertical layout.

Add a 200px x 100px panel and give it a yellow, solid 1px border. Call this panel myBox.

Below myBox add a button with the the text COLOUR.

Add a field called f1 under the button.

2

Add a new function to your myFunctions script:

function colour() {
   java.lang.Thread.sleep(10000);
   controls.myBox.backgroundColor='Tomato';
}

This function sleeps for five seconds before changing the colour of the box. 

3

Add the myFunctions script to your form's list of Client Callable Functions scripts. 

4

Go to your button's Html Element Properties and open the HTML tab.

Choose the onclick event in the Events dropdown list and add the following JavaScript to Code box:

$eb.executeFunction("colour", null, true);

This will execute the colour function synchronously. Run the form  click the COLOUR button and try typing in the field. Note that you're not able to until the synchronous function call is complete. 

5

In the Html Element Properties, comment out the function call (i.e. //$eb.executeFunction("colour", null, true);) and add the following code beneath:

$eb.executeFunctionAsynchronously(null, null, "colour", null, true);

This will execute the colour function asynchronously with no parameters, no success or failure callbacks and with automatic screen refresh when it completes.

6

Run the form again, click the COLOUR button and enter some text into the field. Note that you now don't have to wait for the function to complete before doing this. 

Current Module

Related