How to use custom fields with event rules

Using this method you will allow your application users to select their notification preferences for their vehicles' event rules. This is especially useful in a restricted environment with users with limited roles. You as an administrator will save time with fewer user modification requests.

The users can do it by themselves in a very intuitive way by just modifying the vehicle properties and select the values in the GUI. In our example, we will create a combo box (Custom Field) that is going to be available in the Vehicle Properties (User Access Mask) where the user can select and save which notification type he wants for a speeding alert for that vehicle. The speed limit value is also a property that the user can set to each vehicle and will define the execution of the event rule.


  1. Add the Custom Fields
  2. Modify the User Type
  3. Create a new User Access Mask
  4. Create a new role and assign the Access Mask
  5. Create your Event Rules with the script
  6. Testing

Add the Custom Fields

Read how to enable user custom fields here.

We have to select the Custom Field list and put here all the different notifications that our Event Rules will handle. We have to remember what we have typed in the Item and Value columns because we will call them later in our scripts.


We also want to add another Custom Field called Speed Limit of the type Text


Modify the User Type

Now that we have these Custom Fields set we need to add them to our Vehicles’ properties. To simplify this task we will modify the Device User Type in the User Type Editor.

We select User Type Device, and then we will add our new Custom Fields created previously, under Details


If we edit a Vehicle we can see now the two added Custom Fields



Create your Event Rules with the script

Now we have to create Event Rules for each different notification we want to send. As we created three different choices for our notifications (Email, SMS, Marker, Disabled) we will use three different Event Rules. One for Email, another for SMS, and another for Marker.


Email notification case

When creating your Event Rule, on step 4. Expressions, select Script Expression.

Read how to enable script expressions here.

In this example, we will use a simple Javascript code that will compare the Speed Limit value from the vehicle properties and return true if matches the condition.

A script for the Email notification could be like this:

var notifType = session.user.getCustomFieldValue ('Speeding Alert'); //from the Vehicle properties
var limit = session.user.getCustomFieldValue ('Speed Limit'); //from the Vehicle properties
var speed = fields.get('Speed', null)*3.6; //current Vehicle speed with mt/s to Km/h conversion
if(notifType == 'Email' && speed > limit) return true;
// else
return false;

Remember that the values you are using in the function getCustomFieldValue and the comparison values inside the IF clause should match the values and custom fields labels set up previously.


Select Email as the notification type for this rule


When you've configured your email notification rule, Save it.

SMS notification case

Create a new rule for SMS case.

The SMS and Marker scripts change slightly. On the following images we highlight the changes you need to make:


Marker case

For the Marker notification case, we create a new event rule, and introduce the changes shown below.


We won't select any notification on this step (because we just want a marker on the map, we do that on step 6), we click on Next.


We select our on-map options as below


Save now the rule.


Verify for your vehicle/s which custom fields need to be selected, according to the notification type you with for each vehicle.

1. Edit the vehicle.

2. Input the values for Speeding Alert and Speed Limit.

These values will define which notification (event rule) will be used and at which speeds these alerts will react.


We recommend using the device simulator to test the behavior of these new rules and notifications.