9/20/2022 10:33 AM | |
Joined: 11/3/2021 Last visit: 4/7/2025 Posts: 10 Rating:
|
Hello again, I've been trying to make a script that shows the number of active alarms in an io field, this works fine for me but i would love for the script to switch between two different alarm classes if the first one isnt active. This is what my script looks like at the moment, both the "NumberActiveCritical" and the "NumberActiveNonCritical" are added as triggers in the script. I wish to make it so that if theres critical alarms these will take priority and show in the field, and if there are no critical but there are NonCritical these will show. Im not super familiar with javascripting so any help is more than welcome! export function IO_field_1_ProcessValue_Trigger(item) { let numAlarms; let alarmFilter = "AlarmClassName = 'Critical Alarms'"; let alarmFilter2 ="AlarmClassName = 'Non Critical Alarms'"; let tag1 = Tags("NumberActiveCritical"); let tag2 = Tags("NumberActiveNonCritical"); if (tag1.read()>0) { HMIRuntime.Alarming.GetActiveAlarms(1033, alarmFilter).then( function(numAlarms){ Tags("NumberActiveCritical").Write(numAlarms.length); }).catch(function(errorCode){ Tags("NumberActiveCritical").Write(0); }); return Tags("NumberActiveCritical").Read(); } else if (tag2.read()>0){ HMIRuntime.Alarming.GetActiveAlarms(1033, alarmFilter2).then( function(numAlarms){ // Write number to tag for amount of alarms Tags("NumberActiveNonCritical").Write(numAlarms.length); }).catch(function(errorCode){ Tags("NumberActiveNonCritical").Write(0); }); return Tags("NumberActiveNonCritical").Read(); } } ------------------------------------------------------------------------------------------ |
Last edited by: Jen_Moderator at: 09/21/2022 04:25:56New subject after splitting |
|
9/21/2022 1:42 PM | |
Joined: 4/26/2012 Last visit: 4/25/2025 Posts: 1629 Rating:
|
hello, two things you can try first change tag1.read() by tag1.Read() tag2.read() by tag2.Read() it is an example LINK if (_condition_) { //statements } else { if (_condition_) { //statements } } you can use RTILtraceViewer to debug the running code, using HMIRuntime.Trace(" text"); good luck
|
Last edited by: rdoliveira at: 09/21/2022 13:45:26Last edited by: rdoliveira at: 09/21/2022 14:02:42Last edited by: rdoliveira at: 09/21/2022 14:05:43"Always make a backup before performing any tests |
|
Follow us on