Rule to Associate Asset

Asset associations are a powerful concept, and they can be managed in a few ways. This example shows how an association can be made from a dataitem reported by a device. This would happen when a device can detect that it's near or connected to another device. So this consists of an Expression Rule that runs when a dataitem called "destination" is reported. The string in "destination" will be the serial number of the asset to associate to this device. The Expression Rule looks like this:

The expression evaluates if the destination changes. The "If" must contain the dataitem that triggers the rule. Since its a string, we aren't looking for it to contain some specific value, so this triggers each time it changes.

The rule runs a Groovy script called AssociateAsset which takes 2 parameters:

serialNumber - a string with the serial of the asset to associate
model - the model of the asset to associate

and it also uses the implicit parameter called "context" that passes the current device into the script. Associations have a direction. This script associates the device that triggered the rule as the source, and the device specified by serial is the destination.