Using Triggers


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.

Create Trigger

The first step in creating a trigger is to create your code service that will be executed. In this example, we’ll create a trigger for the Data:ItemCreated event, for items created in any collection. To do this, go to your system/application and click the “Code” tab. Next, enter the javascript for your service as explained in the “Code” section of the documentation. Call the service “myCodeService”.

When you have finished entering the javascript, click on this icon Cog in the upper-right portion of the screen. A dialog will pop up with a set of tabs on top. Select “Triggers”. Your screen should look something like this:

Trigger Dialog

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:

Ready To Create

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.

Update Trigger

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:

  1. Navigate to the “myCodeService” service.
  2. Click on the Cog icon and select the “Triggers” tab.
  3. 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.

Delete Trigger

Deleting a trigger is also very simple. Follow steps 1-3 above, and then click on the Trash Can icon. Tap “Confirm” in the dialog that appears.

Note that deleting a trigger does not delete the code service associated with that trigger.