event.setGlobal not working?

Hi all,

In the notification pipeline I’m trying to add a property to the event.

I’m using the event.setGlobal() method to add the property and set a value.

After the first loop the code exutes correctly and the property is added to the event (checked using system.util.logger).

The event does not exit the pipeline but on the second cycle after a delay the property is not on the event instance.

Is this the correct method of check if the property exist on an event instance?

if 'MessageCount' not in event.properties:
    event.setGlobal('MessageCount',1)

Can someone explain what I am doing wrong?

The event.properties object is not a Python list of Strings, but rather a Java HashSet of Ignition Alarm objects. As such, you cannot use the Python in operator with a String to test if your property is in that set because the HashSet doesn’t contain Strings. Instead, you can iterate through the HashSet and check if the expected property is there. Here is an example of the code I have added to my script block in an alarm notification pipeline to achieve this:

myLogger = system.util.logger("myLogger")
for property in event.properties:
	if str(property) == 'activeTime':
		myLogger.info("Found property!")

Obviously, for your use case, you would swap ‘activeTime’ with ‘MessageCount’.

Thanks this worked