Script to check geofence conditions

This guide shows how you can write a geofence rule that checks if a vehicle is inside a geofence named by a custom field. In this way you can write one single event rule, which checks for different geofences depending on vehicle.

Test setup

1. Create a custom field named Fence.

2. Create a geofence group named Pipelines.

3. Create a geofence called e.g. Pipeline33. Add Pipeline33 to the geofence group Pipelines


4. Edit your test vehicle and set the custom filed "Fence" to "Pipeline33"'


Create Event Rule

Create an Event Rule with a Script Expression like the one below:

// Find geofences at current position.
var fences = geofence.find(trackPoint.position.longitude, trackPoint.position.latitude, 'Pipelines');
var isInside = false;

context.setVariable('PipeName', '-');

if(fences.length > 0)
  // Get name of geofence from Custom Field
  var pipeName = session.user.getCustomFieldValue('Fence');

  if(pipeName != null)
	// Check if named geofence is as current position.
	for(var iIndex = 0; iIndex < fences.length; iIndex++)
	  if(fences[iIndex].name == pipeName)
		isInside = true;
		// Use [PipeName] as variable in Notifiers
		context.setVariable('PipeName', pipeName);

// Return true if inside named geofence.
return isInside;



Use the function context.setVariable() to create variables you can use in the Notifiers. For example, create a Report Argument if you want to create a column in the EV1000 report. Or create an Argument notifier if you want to create on the column in the Event window in the Workspace.


In the example above, the named geofence will be in the variable [PipeName].