# Make display hide and show with a function problem

**URL:** <https://discourse.nodered.org/t/make-display-hide-and-show-with-a-function-problem/83024>\
**Category:** Dashboard\
**Tags:** node-red-dashboard\
**Created:** [20 November 2023 09:43 UTC](https://discourse.nodered.org/t/make-display-hide-and-show-with-a-function-problem/83024 "2023-11-20T09:43:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pepe2](https://avatars.discourse-cdn.com/v4/letter/p/dfb087/32.png) [@pepe2](https://discourse.nodered.org/u/pepe2)\
**Post date:** [20 November 2023 09:43 UTC](https://discourse.nodered.org/t/make-display-hide-and-show-with-a-function-problem/83024/1 "2023-11-20T09:43:03Z")

</div>

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.

```auto
{
    "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:

```auto
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:

```auto
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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [20 November 2023 15:46 UTC](https://discourse.nodered.org/t/make-display-hide-and-show-with-a-function-problem/83024/2 "2023-11-20T15:46:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pepe2](https://avatars.discourse-cdn.com/v4/letter/p/dfb087/32.png) [@pepe2](https://discourse.nodered.org/u/pepe2)\
**Post date:** [20 November 2023 16:02 UTC](https://discourse.nodered.org/t/make-display-hide-and-show-with-a-function-problem/83024/3 "2023-11-20T16:02:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 December 2023 16:02 UTC](https://discourse.nodered.org/t/make-display-hide-and-show-with-a-function-problem/83024/4 "2023-12-04T16:02:34Z")

</div>

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