JavaScript action
Use the JavaScript action to access the Document Object Model (DOM) at runtime.
If you create a Logon form using federated security, a non-editable JavaScript action is created by default. See Federated security.
-
On the form modeling bar, click
Actions and click
New.
The New action dialog box is displayed.
- On the Type list, select JavaScript.
- Change the default Name (JavaScriptAction1) to something meaningful.
- Optional. Enter a Description for the action.
- Optional. Select Multilingual to configure a unique action for each language separately. See Configure multilingual actions.
-
Enter the JavaScript code or reuse a Java script by pasting it in the
Script box. You can also use the following predefined functions to Get/Set
form variables, control values, and global variables on the Desktop, Mobile, and Tablet forms and all capture forms. The controls
and properties that are supported in the Same page action are supported in the JavaScript action.
-
GetGlobalVariableValue(variableName)
-
GetFormVariableValue(variableName)
Get / Update of array form variable is not supported. -
GetControlValue(controlName)
-
UpdateGlobalVariableValue(variableName, value)
-
UpdateFormVariableValue(variableName, value)
-
UpdateControlValue(controlName, value)
If you provide invalid data, such as an invalid variable name or control name in the script, an error message appears.
To use these functions in the JavaScript action, the function should always be prefixed with Forms.SDK. The following are some examples:
Control properties
-
Forms.SDK.UpdateControlValue('textbox1.Label', 'test');
-
Forms.SDK.GetControlValue('textbox1.Label');
Global variables
-
Forms.SDK.GetGlobalVariableValue('CompanyCode');
-
Forms.SDK.UpdateGlobalVariableValue('CompanyCode', 'comp123');
Form variables
-
Forms.SDK.GetFormVariableValue('CustomerName');
-
Forms.SDK.UpdateFormVariableValue('CustomerName', 'TestName');
-
-
Click
Add.
The newly created action is added to the table.
-
Associate the action with the control to trigger this action. See
Configure actions for form control
events. Alternatively, to call this action for a form event, associate the action with the form. See
Associate an action with a form.
You cannot access form elements using JavaScript from the form Onload event.
When a control triggers the action, JavaScript is executed. The script has access to the DOM and is executed on the same page.
See also: