Step 2 - Defining the calling trigger

We will now define the trigger that uses the Execute Lua Script action to call, or "fire", the subtrigger.

To define the example trigger, follow these steps:

  1. From Workbench left pane, select the Projects icon.
    The Projects window appears.
  2. Select or create the MyProject project if needed.
    The project tab appears.
  3. Select the New button from the bottom of the project tab.
  4. In the Name box, type a name for the trigger. We will use the name MyNewTrigger.

  5. From the Event tab, select the Trigger Event Type down-arrow, and then select On-Demand.
  6. Add a Local Variable local_var_string variable with Type of STRING and Length of 16.
    This will be used to contain the subtrigger output.

  7. From the Actions section, select Add.
    The New Action window appears.

  8. Expand the Lua Scripting category, select Execute Lua Script, and then select Add.
  9. In the Lua field of the Execute Lua Script action, enter this Lua script:
    function callsubtrigger(name)
        local sub_in = {subtrigger_in_name=name};
        local s,out = dw.trigger.execute("MyProject","subtrigger",sub_in,"true");
        -- We ignore the status s and return the out string
        return out["subtrigger_out_status"]
    end
    DWOutput["status_string"] = callsubtrigger(DWInput["name"]);

    This Lua script contains one function and one executable line.
    The script is processed from the top down, but the code in the function is not executed until the function is called.
    In this example, we call the function with a name input passed as an input variable from the trigger action and we return a status_string output passed as an output variable back to the trigger action.
    The name input is given to the function, which will then convert it to a proper subtrigger input array sub_in to be passed to the subtrigger.
    The subtrigger will return an output array out and we will use the subtrigger_out_status value from that array. We use that value as the function output.


  10. For the Input tab, map Lua for the name variable.
  11. For the Output tab, map LocalVariables.local_var_string for the status_string variable.

  12. Select Validate to validate the trigger and action parameters. If there are no error reported, select Save.
    If there are errors reported, correct the errors, then select Validate again and then select Save.
Go to: Step 3 - Starting and executing the calling trigger