FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
Dear Community User! We have started the migration process.
This community is now in READ ONLY mode.
Read more: Important
information on the platform change.
01-05-2024 04:28 PM - edited 01-08-2024 08:34 AM
Hello, how to implement the local script for the Dialog Box behavior? F.e. when some var > 50: -> Open the Dialog Box, <= - automatically Close. Thank you in advance.
Solved! Go to Solution.
01-05-2024 05:12 PM
Hi @Hemingway ,
Is this for a WebIQ HMI?
01-08-2024 08:35 AM
Yes, I'm using WebIQ.
01-08-2024 05:18 PM - edited 01-08-2024 05:20 PM
Something like this should work for you. I have a dialogbox widget named "myDialog" opening/closing based on the state of a process variable "bTest". In my local script, I have the following code...
module.run = function (self) {
dialog = shmi.ctrl(".myDialog");
im = shmi.requires("visuals.session.ItemManager");
let tok = null;
tok = im.subscribe(["bTest"], (name,value)=>{
console.log(`New value for item ${name}: ${value}`);
if(value){
dialog.show();
} else {
dialog.hide();
}
});
/* called when this local-script is disabled */
self.onDisable = function () {
tok.unlisten();
self.run = false; /* from original .onDisable function of LocalScript control */
};
};
@CodeShepherd , please move to WebIQ sub.
01-09-2024 08:16 AM
Just a quick note: you should refrain from using shmi.ctrl and only use shmi.onReady as WebIQ is an asynchronous system which means that when your LocalScript runs the dialog might not have been initialized yet so your script would fail. However, it could work perfectly on your system, but on another system or when there is a slow network connection it could fail. That's why you should never rely on "it works on my machine with shmi.ctrl".
Therefore you should always and only use shmi.onReady as shown in this example:
https://demo.smart-hmi.com/demo-animation/js/custom-libs/local-scripts/shapeRotationExample.js
Also, you should not use "dialog = " and "im =", because this would create global JavaScript variables which is usually not intended. You should also prefix those with a "const ".
01-09-2024 09:45 AM
Moved to corresponding forum Smart HMI - WebIQ Designer and Server.