Groovy's Implicit Objects

When an Expression Rule calls a Groovy Script, the Groovy Script is passed one or more implicit objects, depending on the type of Expression Rule.  The object(s) provide information from the environment which caused the Expression Rule to be executed.  This article provides a summary of the implicit objects which may be provided, and pointers to more detailed examples.

This applies whether the GroovyScript is called from the IF section of the rule:

IF:    ExecuteCustomObject("MaximumShakeForce") > 20
THEN:  CreateAlarm("Shake Force has exceeded 20N", 500)

or the THEN or ELSE section of the rule:

IF:    Temp > 40 && Temp < 140
THEN:  ExecuteCustomObject("CheckForSpoilage")

Always Provided

The ActionContext object is always provided to a Groovy script called from an Expression Rule. The variable is named context. The Device is the only attribute that is useful when a Groovy script is called. So in Groovy syntax context.device.name is the current device's name. In Java syntax (which is also allowed in scripts) this would look like context.getDevice().getName()

The following sections summarize the additional object provided, if any, for each type of expression rule.

Alarm, AlarmExtendedDataChange, AlarmSeverityChange, AlarmStateChange

Additional implicit object:  alarm

The alarm object provides information about the alarm which caused the Expression Rule to be executed.

Alarm example

AssetTimer and SystemTimer

Additional implicit object:  none

Data

Additional implicit object:  dataItems which is a list of dataitem objects that are in a message from an agent or from SDK, etc. that caused the Expression Rule to be executed.

File Upload

Additional implicit object: compressedFile

The compressedFile object provides an array of UploadedFile objects from the file transfer which caused the Expression Rule to be executed.  Note that the compressedFile object will be populated whether or not the actual file transferred was compressed.  If a single, uncompressed file is transferred, it will still be described in compressedFile.getFIles()[0].

File upload example

MobileLocation

Additional implicit object: mobileLocation

The mobileLocation object contains the location of the asset whose location report caused the Expression Rule to be executed.

Mobile Location example

Registration

Additional implicit object:  none

StateChange

Additional implicit object: none

UserLogin, UserLogout

Additional implicit object: user

The user object provides information about the user whose login or logout caused the Expression Rule to be executed.

User login example