How to Use Triggers Document


Purpose of this article

This article aims to show what is and how to use the Triggers Document.

1. What is Triggers Document?

The Triggers document is a task that runs in the background, running logical programs (using the built-in scripting language C#), in which execution can be Condition, Trigger, Calendar and interval. Some example uses of the Document Triggers include:

  • Run a Script to generate a report (Daily, weekly or yearly)
  • Run a script after changing a tag
  • Run a script after an alarm is triggered
  • Run a Script whenever an expression is true

It is also possible using a Document Triggers to run a Document Services.

Note: The performance of running the Triggers Documents will depend on the processing of the computer on which ADISRA SmartView is installed. Services documents and triggers have the same execution performance. Both run the scripts in RunTime mode.

Document Triggers is located in the navigation tree. To create a new Document Triggers, follow the steps below:

  • Right-click on the Triggers document located in the navigation tree.
  • Click New Document.

A new document will be shown:

Document Triggers is divided into two areas:

  • Document Settings, which contains a field to enable or disable the document.
  • Triggers Items, which contains all trigger items inserted in the document.

Use the Document Settings parameters in this document as follows:

  • Enable: Enables or disables Document Services. You can also use a boolean tag to enable or disable the document.

The Triggers Document is organized by triggers item. Each document can have several triggers, which can be configured separately. To insert or remove a trigger item, click the “Insert Trigger” or “Remove Trigger” button located in the upper left menu.

Below is an item of triggers inserted in the document. Each triggers item contains a field called “Type”, which defines the trigger type.

2. Types of Execution

2.1 Condition Type

The Condition type executes the trigger item if the condition is “true”. However, it is not possible to set the execution interval as in Document Services. By default the execution interval is 300ms.

Therefore, if we compare the Condition Type of the two Service and Trigger documents, it is possible to notice that the Condition of the Triggers Document will consume three times more CPU processing than the Condition of the Services Document. That’s because the script is running every 300ms. Therefore, if the script does not need to be executed very quickly, it is recommended to use the execution of a longer time interval, so as not to overload the application.

The condition type trigger item has several fields, and these must be filled in according to the type of execution being specified. The fields are:

  • Type: Defines the type of execution (Condition, Trigger, Interval or Calendar).
  • Condition: If the field is true, the trigger item will be executed. In this field it is possible to place a tag, expression or keep it in “true”.
  • Action Type: Defines what will be executed. An expression or a services document can be executed.
  • Expression field: Defines which expression will be executed after the condition field is true.
  • Action field: Defines which Service will be executed after the condition field is true.
  • Alias: Defines a name for the trigger item, so that it can be used by SVEvent functions.

SmartView allows you to create, delete, and view a trigger item using SVEvent functions in RunTime mode. For this, it is necessary to identify each trigger item with an alias, to be used in the parameter of the functions below.


2.1.1 Script Example (Incrementing tag)

According to the example below, whenever the condition “@tagtest == 5” is true, the script will be executed every 300ms.


2.1.2 Script Example (Running a Services Document)

According to the example below, whenever the condition “@tagtest == 5” is true, the Services1 Document will be executed every 300ms.

Note that, if the trigger item executes an expression, it is possible to open a window for script development, clicking on the “…” button.

it is also possible to validate the developed script by clicking on the “Validate” button.


2.1.3 Script Example (Using Alias)

According to the example below, when the command button is clicked in RunTime mode, a script will be executed in the Mouse Up event.

The Script is composed of a function SVEvent.SaveEvent. To use this function, it is necessary to pass the following parameters:

  1. Function to create a new trigger item.
  2. Name of the existing trigger document. If the document does not exist, it will be created.
  3. Trigger item alias.
  4. The type of the new trigger item. 1 to Condition, 2 to Interval or otherwise to Trigger.
  5. The action type of the trigger item. 1 to Service or otherwise to Expression.
  6. The action value of the trigger item. For example, the name of the service for action type Service or the script for the action type Expression.
  7. A string which represents the Condition field of the trigger item.

    After clicking the button above in RunTime mode, the trigger item will be created in the application and accessing the engineering environment, we will find the new trigger item created, shown in the image below.

2.2 Trigger Type

The trigger type executes the trigger item if the trigger tag changes from “False” to “True” or from “True” to “False”.


2.2.1 Script Example (Incrementing tag)

According to the example below, whenever the “@TagBool” tag changes its value, the expression will be executed. In this example, the tag “TagIncrement” will be incremented.


2.2.2 Script Example (Running Function)

According to the example below, whenever the “TagBool” tag changes its value, the expression will be executed. In this example, the SVReport Function will be executed.

2.3 Calendar Type

The “Calendar” type executes a trigger item if the defined DateTime is satisfied. The trigger item can be executed “daily”, weekly or “monthly”. The “Recur to every” field allows executing the trigger item repeatedly every “X” days if it is filled with a value above one.


2.3.1 Script Example (Running function daily)

According to the example below, whenever the datetime is satisfied, the trigger item will be executed daily.


2.3.2 Script Example (Running function weekly)

According to the example below, whenever the datetime is satisfied, the trigger item will be executed weekly, on Monday and Friday.


2.3.3 Sript Example (Running function monthly)

According to the example below, whenever the datetime is satisfied, the trigger item will be executed monthly, in the months January, July and October.

In the “Days” option, it is possible to choose which day of the month the script will be executed.
In the “On” option, it is possible to specify the day of a specific week.

2.4 Interval Type

The “Interval” type delays the execution of a script, that is, we can consider it as a timer.


2.4.1 Script Example (Incrementing a tag every 10 seconds)

According to the example above, every “10 seconds” the trigger item will be executed.



How to Use Services Document


Purpose of this article

This article aims to show what is and how to use the Services Document.

1. What is Services Document?

The Services document is a task that runs in the background, running logical programs (using the built-in scripting language C#), in which execution can be Condition, Trigger or Startup type. Some example uses of the Document Service include:

  • Run a Script to Save a Report
  • Run a script after changing a tag
  • Run a script after an alarm is triggered
  • Run a Script whenever the application starts

Services Document is located in the navigation tree. To create a new Services Document, follow the steps below:

  • Right-click on the Services document located in the navigation tree.
  • Click New Document.

A new document will be shown:

Services Document is divided into three areas:

  • Document Settings, which contains a field to enable or disable the document.
  • Service Settings, which contains run type information.
  • Service Script, which contains the area to insert the script will be used based on the type of execution.

Use the Document Settings parameters in this document as follows:

  • Enable: Enables or disables Document Services. You can also use a boolean tag to enable or disable the document.

Use the Service Settings parameters in this document as follows:

  • Type: Defines the type of execution (Condition or Trigger). It is possible to use an expression in the field where “True” is set. If the expression is true, the script below will be executed.
  • Interval(ms): Defines the time interval that the script execution should occur. The Time value is specified in a format of millisecond (for exemple, 1000 would be 1 second, 10000 would be 10 seconds). There is no minimum and maximum time limit.
  • Description: Defines the document description.

Use the Service Script area to enter the script to be executed according to the type of execution.

Note: The performance of running Services Document will depend on the processing of the computer on which ADISRA SmartView is installed.

2. Types of Execution

2.1 Condition Type

The Condition type execute a script if the condition is true. Then, every X milliseconds, the script entered in the “Service Script” field will be executed. The time interval defined in milliseconds must be informed in the interval(ms) field.

Note: In the field set to true, a tag can be entered. If this tag is set to True, the script will be executed.

2.1.1 Script Example (Incrementing tag)

According to the example below, whenever the condition “@tagTest == 5” is true, the script will be executed every 3000ms.

2.2 Trigger Type

The Trigger type executes a script if the value of the trigger tag changes from false to true or true to false. The trigger tag must be of type Boolean.

2.2.1 Script Example (Incrementing tag)

According to the example below, whenever the trigger tag “@tagBoolean” is true, the script entered in the “Service Script” field will be executed.

2.2.2 Script Example (Running another Services)

It is possible to run the “Service Script” from a services document, even if the chosen condition is not satisfied. For example, if a “Services1();” script is added to the Mouse Down event of a button, the script in the Services1 document will be executed whenever the button is pressed.

2.2.3 Script Example (Incrementing tag)

According to the example below, whenever the trigger tag “ShutDown_App” is true, the script entered in the “Service Script” field will be executed.

2.2.4 Script Example (Assigning value to a tag)

According to the example below, whenever the trigger tag “trigger_date” is true, the script entered in the “Service Script” field will be executed.

2.3 Startup Type

By default, the application automatically creates a Service Document called “Startup”. The script inserted in this service will be executed once every time the RunTime is started.

Note: The Startup Document cannot be removed from the application.

2.3.1 Application example

According to the example below, whenever the application is started, the script will be executed only once, being necessary to restart the application to execute the script again.