# Associated Data in tags AlarmActive event

**URL:** <https://forum.inductiveautomation.com/t/associated-data-in-tags-alarmactive-event/14602>\
**Category:** Ignition\
**Created:** [June 22, 2017, 7:45am UTC](https://forum.inductiveautomation.com/t/associated-data-in-tags-alarmactive-event/14602 "2017-06-22T07:45:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [June 22, 2017, 7:45am UTC](https://forum.inductiveautomation.com/t/associated-data-in-tags-alarmactive-event/14602/1 "2017-06-22T07:45:53Z")

</div>

How can I access associated data from my alarm tag ‘Alarm Active’ event script?  
Currently I have this, but it’s not working:

Associated Data defined

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/ce0c7373fb6301e98586198193095cb179dae689.PNG)

Script in ‘Alarm Active’ event

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/09e1cdfb5b9632c857cbe9f6c5687020353e6842.PNG)

and the error  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/f8e6f00784b847bb3c755ff51da8a48aa688f8f8.PNG)

It seems that **alarmEvent.get(“associated data name”)** is not working in alarm event…?

---

<div class="post-metadata">

**Author:** ![ktran](https://avatars.discourse-cdn.com/v4/letter/k/ecae2f/32.png) [@ktran](https://forum.inductiveautomation.com/u/ktran)\
**Post date:** [June 22, 2017, 9:18pm UTC](https://forum.inductiveautomation.com/t/associated-data-in-tags-alarmactive-event/14602/2 "2017-06-22T21:18:46Z")

</div>

Hi zxcslo, there appears to be a bug with the alarmEvent.get() function in the context of Tag Event scripts. However there is a workaround. Please copy the unicodeDataToDict() and getActiveData() function into your script and call getActiveData() with alarmEvent as the function parameter. This will return a dictionary object in which you can access your associated data with the [] operator. See below for an example.

```python
	# Converts the unicode string returned by activeData.toString() into a python dictionary
	def unicodeDataToDict(unicode):
		import ast
		
		# Makes sure the unicode conforms to dictonary format by doing various string replacements
		unicode = unicode.replace("{", "{'")
		unicode = unicode.replace("}", "'}")
		unicode = unicode.replace('=', "':'")
		unicode = unicode.replace("," , "','")
		unicode = unicode.replace("' " , "'")
		
		# Converts the unicode string to a dictionary object
		return ast.literal_eval(unicode)
	
	# Returns various alarm properties including associated data as a python dictionary
	def getActiveData(alarmEvent):
		activeData = alarmEvent.getActiveData()
		
		# We can't explicilty access the data inside activeData so perform a workaround here.
		# Calling the print() function on an activeData object will return a unicode string containing
		# various alarm property names mapped to its corresponding values.
		# E.g. {name=myAlarm}
		# We will then format this unicode string so that it conforms with the syntax of a python dictionary
		# and then convert into a dictionary object 
		activeDataDict = unicodeDataToDict(activeData.toString())
		return activeDataDict
	
	
			
	activeDataDict = getActiveData(alarmEvent)
	# You can access alarm properties by doing: activeDataDict['NAME_OF_ASSOCIATED_DATA']
	# Note that all values in the dictionary are in string format so it may be necessary 
	# to do some casting.
	deviceName = activeDataDict['deviceName']
	hostname = activeDataDict['hostname']
	

```

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [June 23, 2017, 5:06am UTC](https://forum.inductiveautomation.com/t/associated-data-in-tags-alarmactive-event/14602/3 "2017-06-23T05:06:35Z")

</div>

Cool… It’s working. Thank you. 👏 👍  
Can we expect this bug to be resolved soon?

---

<div class="post-metadata">

**Author:** ![ktran](https://avatars.discourse-cdn.com/v4/letter/k/ecae2f/32.png) [@ktran](https://forum.inductiveautomation.com/u/ktran)\
**Post date:** [June 23, 2017, 3:46pm UTC](https://forum.inductiveautomation.com/t/associated-data-in-tags-alarmactive-event/14602/4 "2017-06-23T15:46:10Z")

</div>

I have submitted a ticket for this bug, but unfortunately there is currently no estimate for when it will be resolved. I will update this thread when it has been fixed.
