Asynchronous considerations for control add-ins

Completed

When you write control add-in objects that work on all display targets, you have to consider some limitations regarding asynchronous communication. All calls between the AL code that is running on the Business Central server and the script method that is running in the web browser are asynchronous.

Therefore, methods in the control add-in interface must be of type void, and property methods should not be used.

To transfer a result from an AL trigger to the calling script method, you need to add a method to the control add-in interface that the AL trigger can invoke to send the result to the script.

To transfer a result from a script method to an AL trigger, you need to add an event to the control add-in interface that the script method can use to invoke an AL trigger that receives the result.

You can use InvokeExtensibilityMethod to invoke an AL trigger on the Business Central server from the page that contains the control add-in.

void Microsoft.Dynamics.NAV.InvokeExtensibilityMethod(name, arguments, skipIfBusy, callback);

Additional information about some of the functions:

  • name - A string that contains the name of the AL trigger to invoke.

  • arguments - An array that contains the arguments to pass to the AL trigger. The arguments must be supplied in an array, even when the trigger only takes one argument.

  • skipIfBusy - A value to indicate whether to invoke the extensibility method if the client is busy. The parameter is optional, and the default value is false.

  • callback - A function that is called when the extensibility method has finished running on the server. This parameter is optional.

The callback function is useful for synchronizing multiple calls with the server.