Based on the value I have to show the text message. I can do this using this in rules / conditions. But the same is required in many pages. To avoid this , I wanted to make a function and pass the value to show the message.
can you help me to create global JS function or provide a link of similiar example.
Simple example: jsVal2Word(0) = "Zero" , (1)="One", (2)="Two"
Do you mean a pop-up message or a value that is displayed in a label / text box, for etc.?
Yes, label
Oh, that's what you mean.
One way is described here in an example project in the old help:
The project:
"Statuswert in Nachricht umwandeln" has an example of this.
https://classicdocs.quickhmi.com/help_quickhmi/actual/online/de/example_projects.html
As an advanced tip that you don't have to call a single Events.onVarChanged function for each variable is that you can also use regex for the names: Here is the code adapted from the example project:
//Example variables: ds.state1 ds.state2 ds.state3 ds.state10 ds.mode1 ds.mode2 ds.mode3 ds.mode10 Datenquelle Intern: Intern.state1 Intern.state2 Intern.state3 Intern.state10 Intern.mode1 Intern.mode2 Intern.mode3 Intern.mode10
//Javascript:
//Messages for a state this is either not numeric, or not starting at index 0.
let stateMessages = {
4711: "Message for state 4711",
"4712": "Message for state 4712",
"NO_CONN": "Message for state 'NO_CONN'",
"ABC123": "Message for state 'ABC123'"
};
function processState(args) {
//Get the message based on the variables value.
let message = stateMessages[args.variable.value];
let _varname = args.variable.name;
//Write the message to the internal variable "stateMessage" that is used in the user interface.
mainInterface.setVariable("Intern." + _varname, typeof message === "undefined" ? "Invalid state value" : message);
}
//Link variables to the handler functions above.
//This can alternatively done by using the "Scripting" -> "JavaScript" -> "Assignment" page.
Events.onVarChanged(/ds.state\d+|ds.mode\d+/, processState);
Thanks, I will try and let you know

