Monitor Specific Historian Event Tag
- Last UpdatedJun 10, 2024
- 3 minute read
-
Follow the steps listed in Trigger Workflow from the Historian Server.
-
Next, you need to create a user-defined attribute (UDA) (by clicking the + sign) for each Historian event tag to trigger a workflow for a Historian event occurrence. The category for the UDA should be User Writeable.
-
Next, write a script to get the triggered event information from Historian.
You need to run the script in asynchronous mode. Select the Runs Asynchronously check box. Sample script is given below:
dim dataTables as System.Data.DataTable;
'Add UDA for each Event Tag; Make all the values of attributes as false here
SQLData_001.On_SysStatusEvent_Trigger = false;
dataTables = Historian.EventScript.HistorianEvent.GetTriggeredEventsForSpecificTag("HistorianDatabaseServerName", "DatabaseName", true, "", "","GalaxyName", "ObjectName", "SysStatusEvent", me.Last_Lookup_Key);
If(dataTables <> null)Then
SQLData_001.On_SysStatusEvent_Trigger = true;
me.Last_Lookup_Key = dataTables.Rows[0]["EventLogKey"]
Endif;
dataTables = null;
Explanation of the script:
-
The Historian.EventScript.dll has one public static method named as GetTriggeredEventsForSpecificTag. The script above shows how to invoke the GetTriggeredEvents method.
-
The GetTriggeredEvents method return type is System.Data.DataTable. The data type will have two columns, EventLogKey and TagName.
-
Last_Lookup_Key is the value of the last EventLog fetched from the Historian database. If the primary server fails for any reason, the backup server will automatically start monitoring the Historian server using the Last_Lookup_Key value.
-
The GetTriggeredEvents method has seven parameters, as described below:
|
Parameter Name |
Datatype |
|---|---|
|
serverName |
String |
|
databaseName |
String |
|
isWindowsAuthentication |
Boolean |
|
userId |
String |
|
passWord |
String |
|
galaxyName |
String |
|
objectName |
String |
|
tagName |
String |
|
lastProcessedNumberRead |
Integer |
Ensure to set the SQLData_001.On_SysStatusEvent_Trigger to false at the beginning of the script.
Associating Workflow Event with System Platform Workflow
-
Next, you create a workflow event to attach the workflow. Select the Workflows tab of SQLData_001.
For event association details, refer to Associate an Existing Workflow to a Workflow Event.
-
Click the + sign to add an event, Historian_Event_script. Select WorkflowGateway_001 from the Workflow Gateway drop-down list and click Select.

-
The Associated Workflows section appears. You can create a new workflow or use an existing workflow to associate with this event.
-
After you add the workflow, it appears in the Associated Workflows list.

-
Next, you need to set the event expression. Click the Expression Editor button on the right side. The workflow gets triggered depending on the Trigger Type selected.

The Galaxy Browser appears.
-
Select SQLData_001, On_SysStatusEvent_Trigger attribute and click OK.

-
The SQLData_001.On_SysStatusEvent_Trigger attribute appears in the EventExpress (OnTrue) box. Add ?==true? after the attribute name and click the Save button.

-
Next, deploy the objects by right-clicking on the SQLData_001 and WorkflowGateway_001 objects and selecting Deploy.

Continue to monitor the EventHistory table of the Historian database. If any matching tags are inserted, the WF_Historian_Tag workflow will be fired.