Create New Messages From Scripts
Now it is possible to create new messages from a script that behave 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.
- Login to SiteAdmin
- Go to Plugins tab.
- Set the Repository URL to: http://update.gpsgate.com
- Under My Plugins tab, make sure that Patch.v4 plugin is installed and up to date (version 22.214.171.12418 or higher).
Examples: creating a new message with a variable value set from the script
You can find more general information on Script Apps here.
Example: Geofence Variable
This example shows how to save visited Geofences in track history.
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:
Now we will create a script that will record the name of the visited Geofence to the a variable. In this example we will use CustomString variable. Make sure that the variable is mapped to an input field in Device Mappers of relevant vehicles.
Create a Notifier Click Script for either of the following examples, first go to Development > App Builder > Add new App and create a new App.
Then to the Click Scripts step, choose Add new Script App, and select Notifier kind.
Link the script to the start of an Inside Geofence event like this:
Then click Edit and specify the following script:
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.
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”.
Example: Driver Variable
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.
Discuss this blog post on the forum please