Update cookies preferences
Promotic

onItemBeforeWrite - event of the PmaData object

Description:
The event is triggered before writing into (the change of) the value of one variable defined on the "Data" tab.
Parameters:
pMe(Object) Reference to the PmaData object where the event rises.
pEvent(Object) Reference to the object describing detailed information about the specific event.
pEvent.Item - (Object) [for reading] The PmVar object containing the information about the variable, in which some writing (change) occurred
pEvent.NewVal - (Variant) [for read and write] New value of the variable.
The variable will have this value after the event ends.
pEvent.NewQuality - (Long) [for read and write] New quality of the variable.
The variable will have this quality after this event ends.
See the PmVar.Quality property.
Note:
To achieve calling this event for the specific variable, it is necessary to:
- Create a data extension ExtWriteAction in the variable.
- enable the calling explicitly in the variable (see the "ExtWriteAction > Data extension ExtWriteAction > Event "onItemBeforeWrite"" configurator).
There it also specifies whether the event is triggered before each writing or before each change of the value.
 
If the triggering is enabled for each variable and writing into (the change of) all variables occurs at a time, then the event is triggered for each variable separately!
The usage of this event is appropriate, for example, to filter written values.
The pEvent.NewVal property is defined for read and write. If a new value is written into this parameter, then the value from the parameter is written as a matter of fact into the object variable (after ending this event).

Caution 1:
It is recommended to use this event only for special cases. When this event is enabled, the values are written in a more complex way.
If the writing is invoked in the main thread then the event is triggered synchronously and the writing is also finished synchronously.
If the writing is called from another thread (web, communication, the PmaSequencer object) then the event is triggered asynchronously, i.e. this event does not triggered the variable write command instantly, but later, after the active script is finished. The delayed asynchronous writing causes the variable to contain the original value even after the writing is reportedly complete, so if such value is then read (script, trends) it still contains the original value.

Caution 2:
The event is triggered only if the real writing is performed (e.g. object.Item(0).Value=3) into the variable - let's mark it A.
But if the data binding (on reading) to another variable B (in another object) is defined in the A variable and it is written into the B variable, then the A variable doesn't know about the change and therefore the event is not triggered (the A variable does know about the change only when it is read by someone - data binding is then "performed" - but the the event is not triggered again !).
See also:
Example:
The following script in the onItemBeforeWrite event dumps the information about the written value into the Debug item of the INFO system - it dumps the name of the variable where it will be written, the index of the variable and an old and new value of the variable.
JavaScriptVBScriptSelect and copy to clipboard

Pm.Debug("Name:" + pEvent.Item.Name);
Pm.Debug("Index:" + pEvent.Item.Index);
Pm.Debug("OldValue:" + pEvent.Item.Value);
Pm.Debug("NewValue:" + pEvent.NewVal);

History:
Pm9.00.18: New pEvent.NewQuality parameter contains the quality of the variable after this event ends.
Pm9.00.10: If the writing is invoked in the main thread then the script is called synchronously so after writing into PmVar from the script the value is already there available for reading.
PROMOTIC 9.0.28 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.