Invoking a Trigger from a Method
While defining your method, it is possible to define it to execute a trigger asynchronously whenever the method is invoked. This section explains how to define a method to fire a trigger. The following example provides you a step-by-step procedure to invoke a trigger via a method.
Part 1: Defining Method while adding or updating Thing Definition
- Start defining the Method and enter the Key. For more information on defining the method, see Defining Methods
Note the Thing definition Key and Method Key, you will need them while defining the trigger
- Select the Trigger from the Handler drop-down
- Click Update/Add
- Create a Thing with the Thing definition you defined. For more information on defining the Thing definition, see Creating a Thing definition
Part 2: Defining the Trigger with method.exec event containing the same key and Thing definition
- Click Developer >> Triggers >> New Trigger
- Drag and drop the method.exec event. For more information, see method.exec event
- Complete the trigger. For example:
- Click Add
- Navigate to the Thing with the Thing definition you defined in the Part 1 and click on the Methods tab.
- When you click on the method then you will be able to fire the trigger
- If you want to return the output from the trigger then you need to use trigger.result action to bring back the desired values
- When you execute your method now, you will get the result.