Alarm Count filter

I want to filter the alarm count according to the path

i used:

if({Alarm Count Label.states} = “”,
0,
toInt(runScript(“len(system.alarm.queryStatus(state=[” +
left({Alarm Count Label.states}, len({Alarm Count Label.states}) - 1) +
“], source=[“ABB”,“ADP”]))”, {Alarm Count Label.UpdateRate}))
)

it works but I want ‘source’ to be changed according to user roles like user roles=[ABB, ADP, other…]

any ideas please?

Have you figured the user roles out yet?

Yes, what do you want to do?

Actually what you used for filtering is exactly what I’m looking for.

I just had an idea about using a client tag for your request though I assumed you might have figure it out already since this was posted in March.

In the alarm count template, add an internal property ‘source’. put something like that:

if(hasRole('operator'),'["prov:default:/tag:O*"]',
if(hasRole('admin'),'["prov:default:/tag:A*"]',
'["prov:default:/tag:*"]'))

then, you have to include the previous property ‘source’ in the property ‘count’ (the one that returns the number of alarms) something like this:

if({Alarm Count Label v2.states} = "", 

	0,
	toInt(runScript("len(system.alarm.queryStatus(priority="+{Alarm Count Label v2.priority}+",state="+{Alarm Count Label v2.states}+",source="+{Alarm Count Label v2.source}+"))", {Alarm Count Label v2.UpdateRate}))
)

thanks for sharing

Just note, if you’re using calls to queryStatus from the Vision gui, you’re going to be decreasing its performance as these calls take a long time relatively and will lock up the gui thread while they run. I’ve had clients perform extremely poorly with these calls.

2 Likes

Do you recommend using a gateway script instead of using an execution script in the expression?

for the alarm counter it would be a gateway script that runs every 5 seconds or so

I use a UDT. Note: you’ll need to create a new Tag Group called ‘Area Alarms’. I set mine to direct 3000ms. You can ignore the Area PLCs for Alarm Reset tag.

image

{
  "typeColor": -65536,
  "readOnly": false,
  "dataType": "Int4",
  "writePermissions": {
    "type": "AllOf",
    "securityLevels": []
  },
  "name": "Area Alarms",
  "readPermissions": {
    "type": "AllOf",
    "securityLevels": []
  },
  "tagGroup": "Default",
  "tagType": "UdtType",
  "enabled": true,
  "tags": [
    {
      "valueSource": "expr",
      "expression": "jsonGet({[.]Alarm Summary}, \u0027ActiveUnacked\u0027)",
      "readOnly": false,
      "dataType": "Int4",
      "writePermissions": {
        "type": "AllOf",
        "securityLevels": []
      },
      "name": "Active Unack",
      "executionMode": "TagGroupRate",
      "readPermissions": {
        "type": "AllOf",
        "securityLevels": []
      },
      "tagGroup": "Area Alarms",
      "tagType": "AtomicTag",
      "enabled": true
    },
    {
      "valueSource": "memory",
      "readOnly": false,
      "dataType": "DataSet",
      "writePermissions": {
        "type": "AllOf",
        "securityLevels": []
      },
      "name": "Area PLCs for Alarm Reset",
      "readPermissions": {
        "type": "AllOf",
        "securityLevels": []
      },
      "tagGroup": "Default",
      "value": "{\"columns\":[{\"name\":\"PLCName\",\"type\":\"java.lang.String\"},{\"name\":\"PLCParentPathOverride\",\"type\":\"java.lang.String\"},{\"name\":\"DisableAlarmReset\",\"type\":\"java.lang.Boolean\"}],\"rows\":[]}",
      "enabled": true,
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "expr",
      "expression": "runScript(\r\n\"shared.alarms.getAlarmSummary(\u0027\" + replace({PathToParentFolder}, \u0027Area Alarms\u0027, \u0027\u0027) + \"*\u0027)\"\r\n,2000\r\n)",
      "dataType": "Document",
      "name": "Alarm Summary",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "expr",
      "expression": "jsonGet({[.]Alarm Summary}, \u0027ActiveAcked\u0027)",
      "readOnly": false,
      "dataType": "Int4",
      "writePermissions": {
        "type": "AllOf",
        "securityLevels": []
      },
      "name": "Active Ack",
      "executionMode": "TagGroupRate",
      "readPermissions": {
        "type": "AllOf",
        "securityLevels": []
      },
      "tagGroup": "Area Alarms",
      "tagType": "AtomicTag",
      "enabled": true
    },
    {
      "valueSource": "expr",
      "expression": "runScript(\r\n\"system.dataset.toDataSet([\u0027source\u0027, \u0027name\u0027],[[str(a.source).split(\u0027:\u0027)[3], a.name] for a in system.alarm.queryStatus(priority\u003d[1,2,3,4], state\u003d[\u0027ActiveUnacked\u0027], path\u003d[\u0027*:/tag:\" + replace({PathToParentFolder}, {InstanceName},\u0027\u0027) + \"*\u0027])])\"\r\n\r\n, 2000\r\n)",
      "dataType": "DataSet",
      "name": "Active Unack Alarms",
      "tagType": "AtomicTag"
    }
  ]
}
1 Like

This looks like it will do exactly what I want, but I can’t see what’s happening at shared.alarms.getAlarmSummary. Can you show what that function is doing?