Click Scripts: create new messages using notifiers
Using notifiers in click scripts makes it possible to create new messages from a script that behaves just like messages sent from a device. Notifier click scripts are scripts triggered when an event starts or ends. RouteMessage click scripts are a new powerful type of script that is executed whenever a device sends a message. In these scripts, you can use the message object to create new messages for the device that triggered the script or for a different device.
Modifying the device track history messages adding geofence information
This example shows how to save visited geofences in track history.
1. You can use the Inside Geofence event rule available in Basic One template, or create a new event rule with a geofence expression like this:
2. In Admin > Device Mappers, map the input Text1 to Custom text
3. Create a notifier click script in Development > App Builder > + New App
4. Now specify a name for your new app and go to 2. Click Scripts > + New Click Script
5. Select the Kind > Notifier type
6. Click Edit and copy-paste the following script:
7. Run the script from the editor to ensure that it works. Note that in a run from the editor expression specified in context.resolve is not resolved but just used as-is.
8. Then save the script.
With this setup, when a message from a vehicle triggers the Inside Geofence rule, another message will immediately be generated for it, containing the name of the geofence as the value of CustomString variable. This variable effectively denotes “name of last visited geofence.”
- Use the device simulator to test if you get the desired results.
- You can see the results directly in the terminal window for example.
You can save driver information to track history in roughly the same way as in the previous example, with the following changes:
- Instead of Inside Geofence rule, use a Driver ID Event Rule
- Use the same script, just with [GEOFENCE_NAME] replaced with [DRIVER_NAME].
This will make CustomString variable contain the name of the last driver.
Avoid circular dependencies
A message created by script X must not end up triggering X again. That will end up in the following error text in the terminal window.