WA EXECUTE JAVASCRIPT FUNCTION
WA EXECUTE JAVASCRIPT FUNCTION ( * ; object : Text ; jsFunction : Text ; result : Variable {; ...param : any} )
WA EXECUTE JAVASCRIPT FUNCTION ( object : Field, Variable ; jsFunction : Text ; result : Variable {; ...param : any} )
WA EXECUTE JAVASCRIPT FUNCTION ( * ; object : Text ; jsFunction : Text ; * {; ...param : any} )
WA EXECUTE JAVASCRIPT FUNCTION ( object : Field, Variable ; jsFunction : Text ; * {; ...param : any} )
| Parameter | Type | Description | |
|---|---|---|---|
| * | Operator | → | If specified, object is an object name (string) If omitted, object is a variable |
| object | any | → | Object name (if * is specified) or Variable (if * is omitted) |
| jsFunction | Text | → | Name of JavaScript function to execute |
| result | Variable | ← | Function result (if expected) |
| * | Operator | → | Function with no result |
| param | any | → | Parameter(s) to pass to function |
Description
The WA EXECUTE JAVASCRIPT FUNCTION command executes, in the Web area designated by the * and object parameters, the JavaScript function jsFunction and optionally returns its result in the result parameter.
If the function does not return a result, pass * in the result parameter.
You can pass one or more parameters containing the parameters of the function in param.
The command supports several types of parameters for both input (param) and output (result). You can pass and retrieve data of the string, number, date, object and collection types. If the parameter type is not defined, the text type is used by default.
Warning: Using this command to call directly a JavaScript function that displays a dialog (alert(), print()...) is not recommended since the user cannot interact with the Web area while the 4D code is running. If you need to implement such interface, for example you can call setTimeout(function(){alert();}, 50)) to let the execution of the 4D code finish and allow user interaction.
Example 1
Calling a JavaScript function with 3 parameters:
$JavaScriptFunction:="TheFunctionToBeExecuted"
$Param1:="10"
$Param2:="true"
$Param3:="1,000.2" //note "," as thousands separator and "." as the decimal separator
WA EXECUTE JAVASCRIPT FUNCTION(MyWArea;$JavaScriptFunction;$Result;$Param1;$Param2;$Param3)
Example 2
The "getCustomerInfo" JavaScript function receive a number ID as parameter and returns an object:
var $Result : Object
var $ID : Integer
$ID:=1000
WA EXECUTE JAVASCRIPT FUNCTION(*,"WA";"getCustomerInfo";$Result;$ID)
Example 3
The WA EXECUTE JAVASCRIPT FUNCTION command can be used to update Qodly sources from a Qodly page embedded in a Web area.
// Set local datasource in a specific page
var $Source;$Value;$Page;$Result : Text
$Value:="New Value"
$Source:="title" // title is the name of string datasource
$Main:="Main" // Main is name of the Qodly page
// the namespace is sent as null, as the it's a local source
WA EXECUTE JAVASCRIPT FUNCTION(*;"WA";"Qodly.setSource";$Result;$Source;$Value;Null;$Page)
//Set shared datasource
var $Source;$Value;$Namespace;$Result : Text
$Value:="New Value"
$Source:="title" // `title` is the name of string datasource,
$Namespace:="shared" // `shared` is the namespace of the qodly source
// Since $NameSpace is defined no need to add the $Page arguments
WA EXECUTE JAVASCRIPT FUNCTION(*;"WA";"Qodly.setSource";$Result;$Source;$Value;$Namespace)
//Set current page local datasource
var $Source;$Value;$Result : Text
$Value:="New Value"
$Source:="title" // `title` is the name of string datasource,
WA EXECUTE JAVASCRIPT FUNCTION(*;"WA";"Qodly.setSource";$Result;$Source;$Value)
See also
Enhance your Desktop Interface with Web widgets using 4D Qodly Pro (blog post)
WA Evaluate JavaScript
Properties
| Command number | 1043 |
| Thread safe | no |