JavaScript action

Use the JavaScript action to access the Document Object Model (DOM) at runtime.

  1. On the form modeling bar, click Actions and click New.

    The New action dialog box is displayed.

  2. On the Type list, select JavaScript.
  3. Change the default Name (JavaScriptAction1) to something meaningful.
  4. Optional. Enter a Description for the action.
  5. Optional. Select Multilingual to configure a unique action for each language separately. See Configure multilingual actions.
  6. 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 a Same page action are supported in the JavaScript action.

    • GetGlobalVariableValue(variableName)

    • GetFormVariableValue(variableName)

      Note 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 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. Following are the 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');

  7. Click Add.

    The newly created action is added to the table.

  8. 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.

    Note You cannot access form elements using JavaScript from the form Onload event.

    When a control triggers the action, the Java script is executed. The script has access to the DOM and is executed on the same page.