Make display hide and show with a function problem

Hi, I'am new to this forum and I don't know if I use it like it should be.

I have a button on my dashboard and if I push on it, the dashboard shows or hide depending items on a fixed payload topic. That works perfect. Now I made a second tab on my dashboard so I can make my own selection what to hide and show on screen, depending on the selection. I made a function to make a payload topic, but I can't get the selection on my screen.

In the picture is the json( hide and show) that works, is the fixed json.

{
    "group": {
        "hide": [
            "Main_OverhevelGame",
            "Main_M17Game"
        ],
        "show": [
            "Main_InGameDisplay",
            "Main_DrukknopGame",
            "Main_BlueRedLineGame"
        ]
    }
}

I made also a function to make a payload with the following result:

20-11-2023 10:15:11node: debug 2
[object Object] : msg.payload : string[84]
"{"group":{"hide":["Main_OverhevelGame","Main_M17"],"show":["Main_BlueRedLineGame"]}}"

the function is like:

var spelhide = "{\"group\":{\"hide\":[";
var spelshow = "],\"show\":[";

if(global.get("speelOverhevel") == true){
    if (spelshow == "],\"show\":["){
        spelshow = spelshow + "\"Main_OverhevelGame\"";
    }
    else{
        spelshow = spelshow + "," + "\"Main_OverhevelGame\"";    
    }
}   
else{
    if (spelhide == "{\"group\":{\"hide\":[") {
        spelhide = spelhide + "\"Main_OverhevelGame\"";
    }
    else {
        spelhide = spelhide + "," + "\"Main_OverhevelGame\"";
    }
}   

if (global.get("speelBlueRedLine") == true) {
    if (spelshow == "],\"show\":[") {
        spelshow = spelshow + "\"Main_BlueRedLineGame\"";
    }
    else {
        spelshow = spelshow + "," + "\"Main_BlueRedLineGame\"";
    }
}
else {
    if (spelhide == "{\"group\":{\"hide\":[") {
        spelhide = spelhide + "\"Main_BlueRedLineGame\"";
    }
    else {
        spelhide = spelhide + "," + "\"Main_BlueRedLineGame\"";
    }
}   

if (global.get("speelM17") == true) {
    if (spelshow == "],\"show\":[") {
        spelshow = spelshow + "\"Main_M17Game\"";
    }
    else {
        spelshow = spelshow + "," + "\"Main_M17Game\"";
    }
}
else {
    if (spelhide == "{\"group\":{\"hide\":[") {
        spelhide = spelhide + "\"Main_M17\"";
    }
    else {
        spelhide = spelhide + "," + "\"Main_M17\"";
    }
}   

msg.payload = spelhide + spelshow + "]}}";
return msg;

At the end of the function I put the output to msg.payload. I think is not the problem?
But I don't know to what topic I have to write it?

Is there somebody that can point me where to find the solution?
Many thanks

You are working with strings, It would be easier if you used objects as that is what you need to feed in to the ui-control.

Look at the debug you created a msg.payload that is a string.
msg.payload needs to be an object.
either rework your function to create an object. Or feed the JSON string through a JSON node.

1 Like

Thanks, I used a json node and now it works.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.