Step 3 - Defining a trigger to use the Execute Lua Function From File action

This page describes how to use the Workbench to define an On-Demand event type trigger that uses the Execute Lua Function From File action.

Components of this example

For this example, the following applies:

  • An On-Demand event type trigger is used, other trigger event types could be used.
  • Reporting will be used to see the details of the trigger execution

Defining the trigger, adding local variables, and setting trigger reporting to On

The following describes how to create a trigger that uses an On Demand event, two local variables, and the Reporting feature:

  1. From Workbench left pane, select the Projects icon.
    The Projects window appears.
  2. Double-click the project you want to add a trigger to.
    The project tab appears.
  3. Select the New button from the bottom of the Projects tab to define a new trigger.
  4. In the Name box, type a name for the trigger.

  5. From the Event tab, select the Trigger Event Type down-arrow, and then select On-Demand.
  6. Next you will add two local variables. You will use these variables when you specify the action for the trigger.
    Select the Local Variables tab. From the Local Variables tab, select Add.
    The New Variable window appears.

  7. Name the variable, and then select the data type (for this example STRING).
  8. Enter a string length of 256, and a default value of This,Is,A,Test,1,2,3,4,5,6.
  9. In the Count box, accept the default value of 1 and select Add.
    The variable is added to the Local Variables tab.
    You will assign this variable as input for the trigger.

  10. Add the second local variable as a STRING, with a count of 10, and length of 8 as shown:

  11. Select Add.
    The variable is added to the Local Variables tab.
    For this example, there are now two local variables defined for the trigger:

  12. Setting trigger reporting to On.
    By default, trigger reporting is set to Off.
    For this example, you will set trigger reporting to On so that each time the trigger executes, a report is generated. The trigger report will be viewed to see the details of the trigger execution.
    Be careful with the trigger reporting feature, as the trigger reports require system resources.
  13. From the Trigger window, click the Settings tab.
     
  14. Select inside the Reporting box to display a list of reporting options and select On.

Adding the Execute Lua Function from File action

In this example we are using the trigger List Editor:

  1. In the Actions section at the bottom of the New Trigger window, select Add to add an action.
    The New Action window appears.

  2. Expand the Lua Scripting category, select Execute Lua Function From File, and then select Add.
    The right pane changes to accommodate the specifics of the Execute Lua Function From File action.

  3. Fill in the parameters for the action as follows:

    Parameter

    Description

    Script File

    The name of your Lua script file. Use the Browse button to search the Staging Browser to locate the file. For this example: /scripts/stringsplit.lua.

    Function Name

    This is the name of the Lua function you want to execute. For this example: stringsplit.

    The parameter values appear as follows:

  4. Next to Input Variables, click Configure to define the input variables that will pass data to the Lua function.
  5. When the Variables window appears, select Add.

  6. For this example, a single input named IN of type STRING is added. Enter the Length value as 256 and leave the default Count.
  7. Click Add, and then click OK.
    The variable is added to the Input tab.

  8. From the Input tab, on the IN row, click the Value column.

  9. Locate and expand LocalVariables, and then select the appropriate local variable. For this example, in.
  10. Next, you will define what variables you want to pass back from the script when it executes.
  11. Next to Output Variables, select Configure.
  12. When the Variables window appears, select Add.
    The New Variable window appears.

  13. For this example add a single output named OUT, of type STRING, and set Count to 10.
  14. Select Add, and then select OK.
    The variable is added to the Output tab.

  15. From the Output tab, on the OUT row, select the Value column.

  16. Locate and expand LocalVariables, and then select the appropriate local variable. For this example, out[0].
    The variable is added to the Value column.

Saving, starting, and executing the trigger

You can now validate and save the trigger. After saving the trigger, you will start the trigger so that it can be executed. In addition, the project that the trigger belongs to must also be started.
Remember that this is an On-Demand event trigger, which means it can be executed manually from the Triggers window.

  1. Click Validate. If no errors are reported, select Save.
    If any errors are reported, correct the errors, select Validate again and then select Save.
    The trigger is added to the project tab.

  2. Right click the trigger to display its pop-up menu, and then select Start.
    The State column for the trigger changes to Started.

  3. Right click the trigger to display its pop-up menu, and then click Fire Trigger.
    This will cause the trigger to execute, which in turn will execute the actions defined in it. In this example, there is just the one Execute Lua Function From File action.

Viewing the trigger report

Because the trigger reporting setting was set to On, a trigger report will be generated each time the trigger executes.
To review the report:

  1. From the Workbench left pane, expand Logs & Reports.

  2. From the right pane, select the Reports tab.

  3. In the top half of the Reports window lists the reports by project and trigger name.
    Select the trigger report, the lower portion of the Reports window provides a report viewer.

  4. Right click the report in the lower portion of the window and then select Expand All to expand all sections of the trigger report.
    The report of the trigger's execution will show the action and the variables and show that your script split the string into its individual parts.
  5. Remember to turn reporting off after you have finished developing and debugging a trigger.
    The trigger reporting feature takes system resources, and use during regular execution may degrade performance.