Build alarm that includes username of user who last modified tag

Is there any way to include the client username of the last person to modify a tag in an alarm label? Its been requested that the alarm banner displays an alarm anytime a setpoint is changed and the label would read like “user: Tim changed setpoint to 101”. I know I could build a Mysql table to track this myself, but the users really want this to show up in the alarm banner and I’m not sure how to make this happen.

You could experiment with the audit system. You could query the audit tables to retrieve the last record for that tag when the on-change alarm triggers (as associated data). I’m not sure if the audit record will be in place in time, though.

Thanks, I’m working towards that.

I made a script in the global script library to return the user properly. It works when testing it out in the script console but not when trying to return it in an expression.

def getLastModifiedBy(tagPath):
queryText = “SELECT ACTOR FROM audit_events WHERE ACTION = ‘tag write’ AND ACTION_TARGET like '%” +tagPath+ “’ ORDER BY EVENT_TIMESTAMP DESC LIMIT 1”
username = system.db.runScalarPrepQuery(queryText)
return username

Try adding the database name to your system.db.runScalarPrepQuery(). When you call it from the script console it uses the default database for the project you have open. When you call it from a tag though, the tags are global and not part of a specific project so you need to specify the database.

1 Like