propertyChange script with Internal property not running

Hi all, I’m trying to run a property change script whenever the alarm count (gateway tag) changes to write Unack and Ack count of an area into two memory tags.

I setup an Internal property in my template called alarmChange and linked it to System>Gateway>Alarming>Active and Unacked tag.

I have it setup as follows

if event.propertyName == "alarmChange":
	
	area1path1 = "[default]ClientTags/Alarming/AreaName/Unack"
	area1path2 = "[default]ClientTags/Alarming/AreaName/Ack"
	paths = [area1path1, area1path2]
	
	area1state1 = ["ActiveUnacked"]
	area1state2 = ["ActiveAcked"]
	
	area1tag1 = system.alarm.queryStatus(source=["*AreaName*"], state = area1state1)
	area1tag2 = system.alarm.queryStatus(source=["*AreaName*"], state = area1state2)
	
	area1value1 = len(area1tag1)
	area1value2 = len(area1tag2)
	values = [area1value1, area1value2]
	#event.source.getComponent('testing').text = str(area1value1)+str(area1value2)
	
	system.tag.writeBlocking(paths, values)

The issue is that this seems to be not running from the template.

I’m able to write the values from script console.

I have another template with alarmChange internal property that is running a different script and is working fine. I’ve tried deleting the internal property and setting it up multiple times and it worked once and then stopped again.

Note: The “testing” text field returns nothing in the template.

Any help is appreciated.

Thanks

First up, this isn’t a good idea to run the alarm query status function from the gui. You will lock up the gui thread and significantly impact performance, especially if you have more than 1 of these templates on the page. In the gui thread, you should also use writeAsync whenever you can for the same reason (such as here).

As for the reason it’s not working, pretty sure it’s because of what you’re trying to write to the tags. The results from the query are AlarmQueryResult objects, not tagpaths. You can’t write these objects to a tag. You would need to pull out the info you want from these objects first, such as the source. E.g. area1tag2.getDataSet().getValueAt(0, 'Source')

Hi nminchin,

Thanks for your reply. It works now without having to do any changes to the script from my first post. It was probably because of a different issue I was facing in the morning.

I’m new to Ignition. Is there a better way to do this? What do you suggest I do do get what I want. I’m just trying to get Alarm Unack and Ack count from different areas and store them in a memory tag.

Thanks

This is much better than running it in the gui, but note my post at the bottom: if you're creating many instances of this udt, then you're better off doing as I mention in that post

1 Like

Thanks for that, I’ll look into this option.