Alarm Display Path "Description" from SQL Table

I am trying to run a script that calls a SQL query to to look up and display an alarms Display Path (description). I have the alarm “descriptions” in a SQL table along with a unique alarm code for each alarm. Currently I am testing using an expression in the Alarms Display Path - runScript(“project.myfuncts.get_alert_desc(500)”).
Where ‘get_alert_desc’ is the script and 500 is the unique alarm code.

get_alert_desc:

def get_alert_desc(code):
#function gets the Alert Description from the SQL Database and
#populates the Description field
import system
try:
query = "SELECT * FROM FaultList WHERE FaultNumber = " + str(code)
data = system.db.runQuery(query)
desc = str(code) + " - " + data[0][“FaultDescription”]
return desc
except:
return "No Description Found for Fault Code: " + str(code)

When i trigger the alarm, i get the alarm tags folder and tag name of the alarm tag. In my case it is TEST_Alarm\TestAlarm1

Is there a way to query alarms and retrieve alarm descriptions from a SQL database. I think it might be easier to manage once set up and also easier to change without having to open the gateway.
Thanks,

Yes you can do this, I am doing the same thing but a different method. It’s been while since I figured it out and I’ll be traveling this week so I might not have time to review it in detail for you but I’ll tell you what I remember doing best I can.

I am using a gateway script to monitor my alarm tags so upon a value change the SQL query runs and returns the appropriate alarm message for the particular alarm code value. The script is triggered, the SQL query ran and the result is stored into into a memory string tag. If I recall, the the same tag that triggers the gateway script is configured for tag alarming.

I had the same issue you are describing, the display path was configured to the memory tag that was storing the SQL generated alarm message, yet the alarm still only shown the tag path. I ended up putting a .1 sec delay on the alarm. I believe this allowed enough time for the gateway script to run and populate the tag. Then the alarm was able to capture the text in my memory tag for display. Once I figured that out things work quite well. However, it seems the only time the display path text is grabbed is when the alarm is first triggered. So if the alarm code changes, the tag does not update. The alarm must transaction back to “0” and re-triggered in order to update. Depending on how you react to alarms this may or may not be suitable.

If I am correct, your script wont work due to the timing of when it is triggered to when it grabs the text to display as I believe it acts like a “one-shot”, and does not continuously update the display path once the alarm is active. Right now, your alarm is active, display path text is captured, then your script runs to get the alarm message you want, but the display path will not update after this initial trigger. You need to generate the message first, then activate the alarm.

Thanks for the info Paullys50. I see what you mean by the timing of the query being too late. I will re-think this start looking at a Gateway Script method like you suggested. If you have time when you get back, a screen shot of your Gateway code would be appreciated. Thanks again for taking time to assist!

ccooper -

My gateway code won’t help you much. All it does is trigger a script in my project library to run the error query on the SQL database, and it returns the error text to a memory string tag. The error code function is fairly in-depth because we build our alarm text based on the system, process and device that produced the error code.

Basically:
1 - Data Change script runs on new alarm code detection.
2 - Data change script calls function in my project script library to build error text from SQL database.
3 - error text result is written into a error string tag.
4 - Same tag that triggered the data change script is configured to trigger an alarm if error tag != 0
5 - Alarm display path is configured to look at the error text string tag from step 3.
6 - Alarm has a .1 sec active delay.