Working with Rules

The Lua scripts belonging to Rule items have a few particularities that need to be pointed out. The rules are used to manipulate discovered objects so, in order to access these objects, the script returns a function which implicitly gets as argument the currently found object.

return function(obj)
    obj.ArchiveOptions.StorageStrategy = "STORE_RAW_HISTORY"
    obj:commit()
end
If the script returns nothing or anything else than the above strings, its action is interpreted as "CONTINUE".

A shortcoming of the scripts executed inside rules is that no functions which take as argument the path of the discovered object can be executed. Moreover, setting dynamic properties of these objects is not possible. Discovered objects can only be modified by manipulating their table as in the example below:

return function(obj)
    obj.ObjectDescription = "Test"
    obj.DecimalPlaces = 0
    obj.OpcEngUnit = "bps"
    obj:commit()
    return "CONTINUE"
end
The following functions have no effect when the argument is the rule target object: syslib.deleteobject, syslib.disableobject, syslib.enableobject. Alternatively, the corresponding string actions can be used in order to achieve the same effect: "DISCARD", "DEACTIVATE" (or "DISABLE") and, respectively, "ACTIVATE" (or "ENABLE").