Working with triggers is very simple. You can create, update and delete triggers just like any other object in the ClearBlade system. Each trigger consists of a name, an event to handle (with or without filters), and a code service to be executed when the trigger “fires”. This section shows you how to triggers are created and manipulated from the ClearBlade console.
Click on “Add Trigger +”. In the dialog that appears, enter “anyItemCreated” in the “Name:” field. In the “Source:” pulldown menu, select “Data”. When you do this, and “Action:” dropdown menu will appear. Click on that, and select “ItemCreated”. One more dropdown will appear, titled “Collection:“. Leave that blank.
At this point, the dialog should look like this:
Now, go ahead and click the “Apply” button. Your trigger has been created and is immediately active. Any future items that are created will cause “myCodeServce” to be executed.
Updating an existing trigger is very easy. The only thing you can update for an existing trigger are its filters – the things specific to the actual trigger/event itself. For example, in the trigger we created above, we can only update the collection associated with the trigger. To do that, do the following:
- Navigate to the “myCodeService” service.
- Click on the icon and select the “Triggers” tab.
- Find the “anyItemCreated” trigger and select any collection (assuming you have at least one collection in your application).
The “anyItemCreated” trigger will now only “fire” when an item is created in that collection.
Deleting a trigger is also very simple. Follow steps 1-3 above, and then click on the icon. Tap “Confirm” in the dialog that appears.
Note that deleting a trigger does not delete the code service associated with that trigger.