Handling session variable events in JavaScript: proper placement

Hello,

I have a session variable bound to an OPC UA variable, and I would like to react to a change of the session variable ShowAcknDialog by opening a dialog. There is no problem when using the XML editor:

However, there is a problem when this logic is rewritten in JavaScript:


No action is performed, even though the variable ShowAcknDialog is definitely changing.
The dialog does open when triggered by other events (for example, a widget click).

What are the differences between XML and JavaScript in how session variable events are evaluated?
In which file should the JavaScript code be placed?

Thank you.
Regards
Michal Malek

Hi,

you have to create a new file .eventscript and then also add it to your vis file.

The name of the script is added in the comments

Hi Stephan,
As I wrote, there is no problem with the script when other kinds of events are processed.
And of course, I have a separate file for each piece of content, and all of them are included in the .vis file.

However, the session variable does not belong to any content at the time it changes; only the action leads to the dialog content being loaded. The same behavior is observed in any eventScriptSetId: the session variable change is ignored, even though it clearly changes (as observed on the diagnostic page).

Thank you
Regards
Michal

Hi Michal,

I just tried and it seems to work with mappView 6.5. What version are you using?

Stephan

Hi Stephan,
I also have MV 6.5.
In the meantime, I found a clue. When using a different variable ShowAcknDialogX, which is bound directly:
obrázok

it works exactly as you described.

However, the original variable ShowAcknDialog is bound via a listElement:


because there are multiple different users.

Even so, its value certainly changes (from 0 to 1):


Unfortunately, this clue doesn’t make sense to me yet :-).

Do you see any connection between these observations?

Thank you
Regards
Michal

I tried a list binding like yours and it works as expected. When ShowAcknDialogX works, what happens when you use that variable in your list binding? Also check the logger to see if there is any error message. I attached my sample so you can check what might be different.

Use the last input field to set the session variable.

mappViewSample1.zip (114.5 KB)

Stephan

Hi Stephan,
Thank you for your project.
It seems that the question about where the script should be inserted was the most relevant. It was a bit of a silly mistake on my part, but my intention was to place it in the file related to the dialog that is being opened.
Thank you for your effort.
Best regards
Michal

Hi Stephan,
I have one last question regarding this topic. In XML mode, I have a single EventBinding for a session variable value change that applies to the entire visualization. Regardless of which content is displayed, the dialog is opened.

Is it possible to achieve the same behavior using event scripts? At the moment, it seems that the script must be included in each JavaScript file where the event should occur.

Thank you.
Regards
Michal

Hi Michal,

in general the scripts should have the same functionality as event bindings. Its just an extension of what you get in a simplified way with event bindings and actions. I am not sure what you mean with

At the moment, it seems that the script must be included in each JavaScript file where the event should occur.

If the event is a session variable it should be independent from the content that is displayed. Can you explain that in more detail?

Stephan

Hi,

Remove the “contentId” from your script.

If a contentId is present in the script, the script will be content related, which means it is only active, if the content is active, too. If there is no contentId, it is always active, regardless of the active content.

Please notice that “global” scripts cannot reference content related data (e.g. widgets).

CHH

1 Like

Hi Stephan, Christian,
thank you for the explanation. Now everything is completely clear and works as it should.

Regards
Michal Malek

1 Like