Skip to content

Using Javascripts

Javacripts on WorkHub24 can process data in form fields and form variables.

Some examples of how Javascripts are used:

  1. Form validations, such as ensuring the user selects dates are in the future, or with a specific range from another date.
  2. Adding leading zeros to characters if they are shorted than a specified length.
  3. Calculating the number of days between two dates.
  4. Passing script outputs in the HTTP request body.

Methods to obtain outputs from Javascripts

  1. Using scripts with Compute -Use the “Return” statement on the script to specify the value that should be returned on a form field. You can also assign values to other fields and form variables on the script.
  2. Using Event Handlers (Actions) - Actions such as on click, on focus out, etc. can be used to trigger scripts based on user interactions or form events; with this approach, you can assign values to form fields and form variables.

Examples to obtain an output from Javascripts for form fields.

Section titled “Examples to obtain an output from Javascripts for form fields.”
  1. The first example involves using the Compute feature; with this approach, the output from the JS is generated on a field using the JS return statement.

    Example: Concatenate two Fields and show it in a seperate field.

    Concatenate First Name and Last Name

  2. The second example uses Event Handlers (Actions) with this approach, the output from the JS is assigned to a form field.

    Example: When the user selects a date, the year should be picked in text on a seperate field.

    Get the Year from Invoice Date

Steps to Create Javascript Operation

  1. On the tab click on .

  2. Click on .

  3. Enter a name for the script and hit .

  4. Enter the script on the editor.

  5. To refer to a form field/form variable on the script; on your keyboard hit CTRL + SPACE. Type the the name of the form field/form variable you want to refer. You will see a list of fields/variables with the matching name you entered. Use the arrow keys on on your keyboard to select the form field/form variable and hit enter.

Figure 1 shows a list of variables when you hit CTRL + SPACE and type “variable.”

Figure 1 -Look up Form Variables

Figure 2 shows the result after selecting a variable using the arrow keys to navigate through the list and hitting “enter” on your keyboard.

Figure 2 - Result after Selection of a Form Variable

Figure 3 shows a list of fields. when you hit CTRL + SPACE and type “field.”

Figure 3 - Look up Form Fields

Figure 4 shows the result after selecting a form field using the arrow keys to navigate through the list and hitting “enter” on your keyboard.

Figure 4 - Result after Selection of a Form Fields

How to troubleshoot Javascrpits using the Browser’s Developer Tools

Section titled “How to troubleshoot Javascrpits using the Browser’s Developer Tools”