Notifications
Clear all

Open a page based on External tag value

2 Posts
2 Users
0 Reactions
22 Views
Posts: 2
Member
Topic starter
 

Does anyone have sample code for how to open a QHMI page based on the value in an external tag. Regards Ross


 
Posted : 14/09/2026 11:37 p.m. CEST
Matthias
Posts: 36
Member Admin
 

Hello Ross,

here is an example. The first handler opens a popup when a BOOL tag changes to true, the second one opens a page depending on the number in an INT tag. Replace the tag and page names with your own.

// Open a popup when a BOOL tag changes to true
Events.onVarChanged("PLC.ShowPopup", function (args) {
    if (args.variable.value === "true" && args.variable.lastvalue !== "true") {
        mainInterface.openView("MyPopup");
    }
});

// Open a page depending on the number in an INT tag
Events.onVarChanged("PLC.PageNumber", function (args) {
    var pages = { "1": "Overview", "2": "Motors", "3": "Alarms" };
    var page = pages[args.variable.value];

    if (page && args.variable.value !== args.variable.lastvalue) {
        mainInterface.openView(page);
    }
});

Tag values arrive in the script as text, so a BOOL tag contains "true" or "false" (see mainInterface.getVariable in https://docs.quickhmi.com/en/dokumentation/definition-en/api-functions/ ). That is why the example compares with "true" in quotes: if (value == true) never matches, and if (value) would also match "false". The check against lastvalue makes sure the page only opens when the value has actually changed and not on every update of the tag ( https://docs.quickhmi.com/en/dokumentation/definition-en/variable-change-events/ ).

openView only needs the name of the page, it works for pages and popups, and the group the page is in doesn't matter.

Best regards


This post was modified vor 12 Stunden by Matthias
 
Posted : 17/09/2026 11:00 a.m. CEST