Template Node - Pass through messages from input

I am using a script in a template node and I have noticed that the template node is not passing the input message through even though the Check box is selected.

the flow is a function node followed by a template node:
image

image

I only get a output from the function node. The template node does not forward the input.

Comments appreciated

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

I know how to post code. The issue is not the code the issue is the ui template is not passing the input to the output of the ui_template. I have been testing it and it is not consistent . Some times I can get it to pass the msg, other times I can not. I am going to have to re write the code to flow the function output to ui_template inputs and abandon the ui_template pass on input feature.

Regards

Yes but how is anyone to test this for you?
No one is going to retype all that code, when it is easy for you to post it correctly.
If you want help then best to post code correctly as @smcgann99 pointed out.
A simple test on my device has no issues passing msg(not using your code).

Here is the code if you want to test

[{"id":"8a3e2c11336694f0","type":"function","z":"9ec2f6199a0c95c5","name":"formatGdx","func":"var issue_dt = msg.payload[0].issue_datetime\nvar est = new Date()\nif (msg.payload[0].message.match(/[A][L][T][K][0-9][0-9]/) === null || msg.payload[0].message.match(/[A][L][T][K][0-9][0-9]/) === 'undefined'){\n    msg = { topic: 'gdx', gdx: 0, color: '#808080', }\n    return msg  \n}\nif (msg.payload[0].message.match(/[A][L][T][K][0-9][0-9]/) !== null ) {\n    var geo = msg.payload[0].message.match(/[A][L][T][K][0-9][0-9]/)\n    var gdx\n    if (geo[0].substr(5, 1) <= '4') {\n        msg = { topic: 'gdx', gdx: 0, color: '#808080', }\n        return msg\n    }\n    if (geo[0].substr(5, 1) === '5') {\n        msg = { topic: 'gdx', gdx: 1, color: '#ffff00', }\n        return msg\n    }\n    if (geo[0].substr(5, 1) === '6') {\n        msg = { topic: 'gdx', gdx: 2, color: '#ffbf00', }\n        return msg\n    }\n    if (geo[0].substr(5, 1) === '7') {\n        msg = { topic: 'gdx', gdx: 3, color: '#ff8000', }\n        return msg\n    }\n    if (geo[0].substr(4, 1) === '8') {\n        msg = { topic: 'gdx', gdx: 5, color: '#ff4000', }\n        return msg\n    }\n    if (geo[0].substr(5, 1) === '9') {\n        msg = { topic: 'gdx', gdx: 6, color: '#ff0000', }\n        return msg\n    }\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":420,"wires":[["4de6d090037b846d","452abdc1fce7e54e"]]},{"id":"8238c9becbb9e3fe","type":"http request","z":"9ec2f6199a0c95c5","name":"getGeoJson","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://services.swpc.noaa.gov/products/alerts.json","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":290,"y":420,"wires":[["8a3e2c11336694f0"]],"info":"# getGidx"},{"id":"4de6d090037b846d","type":"ui_template","z":"9ec2f6199a0c95c5","group":"e357ef02.ef3cb","name":"G","order":7,"width":0,"height":0,"format":"<script>\n    (function(scope) {\n        //hide this card. NOTE: 4b689f7473831a84 is the Node id as \n        //seen in the INFO panel on the sidebar when you select this node\n         $('[node-id=\"740726d30c1abb76\"]').hide();\n        scope.$watch('msg', function(msg) {\n            if (msg && msg.topic == \"gdx\") {\n                $(\"#header-gdx\").text(msg.gdx).css(\"color\",(msg.color));\n            }\n        });\n    })(scope);\n</script>","storeOutMessages":false,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","className":"","x":630,"y":420,"wires":[["a12c01c1d147b97a","452abdc1fce7e54e"]],"info":"# Update Server K\n\n# Node links to Solar Flow logic for K index varible #kdx\n\nNode needs to be in one flow for each dashboard tab in order for toolbar to update \n\n\n"},{"id":"a12c01c1d147b97a","type":"ui_template","z":"9ec2f6199a0c95c5","group":"c9165343995892c6","name":"G","order":7,"width":0,"height":0,"format":"<script>\n    (function(scope) {\n        //hide this card. NOTE: 4b689f7473831a84 is the Node id as \n        //seen in the INFO panel on the sidebar when you select this node\n         $('[node-id=\"740726d30c1abb76\"]').hide();\n        scope.$watch('msg', function(msg) {\n            if (msg && msg.topic == \"gdx\") {\n                $(\"#header-gdx\").text(msg.gdx).css(\"color\",(msg.color));\n            }\n        });\n    })(scope);\n    msg = msg.payload\n    return msg;\n</script>","storeOutMessages":false,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","className":"","x":770,"y":420,"wires":[[]],"info":"# Update Server K\n\n# Node links to Solar Flow logic for K index varible #kdx\n\nNode needs to be in one flow for each dashboard tab in order for toolbar to update \n\n\n"},{"id":"2d2bffcc69ac3dec","type":"inject","z":"9ec2f6199a0c95c5","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":420,"wires":[["8238c9becbb9e3fe"]]},{"id":"452abdc1fce7e54e","type":"debug","z":"9ec2f6199a0c95c5","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":640,"y":500,"wires":[]},{"id":"e357ef02.ef3cb","type":"ui_group","name":"Page 1","tab":"4bc17c6e.b74934","order":2,"disp":false,"width":"6","collapse":false,"className":""},{"id":"c9165343995892c6","type":"ui_group","name":"Page 2","tab":"8f4542aa.faf2","order":1,"disp":false,"width":"6","collapse":false,"className":""},{"id":"4bc17c6e.b74934","type":"ui_tab","name":"Page 1","icon":"wi-wu-tstorms","order":5,"disabled":false,"hidden":false},{"id":"8f4542aa.faf2","type":"ui_tab","name":"Page 2","icon":"wi-wu-tstorms","order":8,"disabled":false,"hidden":false}]

I re-read your OG post, from it how are we supposed to know that there is no payload being sent in the OG message.

You have 3 options
1 raise an issue against the github for the node.
2 pass the message around the node, which you seem to be doing
3 add a payload and remove it latter if not required.

Made test case, the passthrough functionality works as expected.

In your code there is syntax you can't use like you have done, but that I think is not directly related to the problem

image

This code shows the issue..

[{"id":"8a3e2c11336694f0","type":"function","z":"9ec2f6199a0c95c5","name":"formatGdx","func":"var issue_dt = msg.payload[0].issue_datetime\nvar est = new Date()\nif (msg.payload[0].message.match(/[A][L][T][K][0-9][0-9]/) === null || msg.payload[0].message.match(/[A][L][T][K][0-9][0-9]/) === 'undefined'){\n    msg = { topic: 'gdx', gdx: 0, color: '#808080', }\n    return msg  \n}\nif (msg.payload[0].message.match(/[A][L][T][K][0-9][0-9]/) !== null ) {\n    var geo = msg.payload[0].message.match(/[A][L][T][K][0-9][0-9]/)\n    var gdx\n    if (geo[0].substr(5, 1) <= '4') {\n        msg = { topic: 'gdx', gdx: 0, color: '#808080', }\n        return msg\n    }\n    if (geo[0].substr(5, 1) === '5') {\n        msg = { topic: 'gdx', gdx: 1, color: '#ffff00', }\n        return msg\n    }\n    if (geo[0].substr(5, 1) === '6') {\n        msg = { topic: 'gdx', gdx: 2, color: '#ffbf00', }\n        return msg\n    }\n    if (geo[0].substr(5, 1) === '7') {\n        msg = { topic: 'gdx', gdx: 3, color: '#ff8000', }\n        return msg\n    }\n    if (geo[0].substr(4, 1) === '8') {\n        msg = { topic: 'gdx', gdx: 5, color: '#ff4000', }\n        return msg\n    }\n    if (geo[0].substr(5, 1) === '9') {\n        msg = { topic: 'gdx', gdx: 6, color: '#ff0000', }\n        return msg\n    }\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":460,"wires":[["4de6d090037b846d","452abdc1fce7e54e"]]},{"id":"8238c9becbb9e3fe","type":"http request","z":"9ec2f6199a0c95c5","name":"getGeoJson","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://services.swpc.noaa.gov/products/alerts.json","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":370,"y":460,"wires":[["8a3e2c11336694f0"]],"info":"# getGidx"},{"id":"4de6d090037b846d","type":"ui_template","z":"9ec2f6199a0c95c5","group":"e357ef02.ef3cb","name":"G","order":7,"width":0,"height":0,"format":"<script>\n    (function(scope) {\n        //hide this card. NOTE: 4b689f7473831a84 is the Node id as \n        //seen in the INFO panel on the sidebar when you select this node\n         $('[node-id=\"740726d30c1abb76\"]').hide();\n        scope.$watch('msg', function(msg) {\n            if (msg && msg.topic == \"gdx\") {\n                $(\"#header-gdx\").text(msg.gdx).css(\"color\",(msg.color));\n            }\n        });\n    })(scope);\n</script>","storeOutMessages":false,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","className":"","x":710,"y":460,"wires":[["a12c01c1d147b97a","3c1aa1184bf3af92"]],"info":"# Update Server K\n\n# Node links to Solar Flow logic for K index varible #kdx\n\nNode needs to be in one flow for each dashboard tab in order for toolbar to update \n\n\n"},{"id":"a12c01c1d147b97a","type":"ui_template","z":"9ec2f6199a0c95c5","group":"c9165343995892c6","name":"G","order":7,"width":0,"height":0,"format":"<script>\n    (function(scope) {\n        //hide this card. NOTE: 4b689f7473831a84 is the Node id as \n        //seen in the INFO panel on the sidebar when you select this node\n         $('[node-id=\"740726d30c1abb76\"]').hide();\n        scope.$watch('msg', function(msg) {\n            if (msg && msg.topic == \"gdx\") {\n                $(\"#header-gdx\").text(msg.gdx).css(\"color\",(msg.color));\n            }\n        });\n    })(scope);\n    msg = msg.payload\n    return msg;\n</script>","storeOutMessages":false,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","className":"","x":850,"y":460,"wires":[[]],"info":"# Update Server K\n\n# Node links to Solar Flow logic for K index varible #kdx\n\nNode needs to be in one flow for each dashboard tab in order for toolbar to update \n\n\n"},{"id":"2d2bffcc69ac3dec","type":"inject","z":"9ec2f6199a0c95c5","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":460,"wires":[["8238c9becbb9e3fe"]]},{"id":"452abdc1fce7e54e","type":"debug","z":"9ec2f6199a0c95c5","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":720,"y":540,"wires":[]},{"id":"3c1aa1184bf3af92","type":"debug","z":"9ec2f6199a0c95c5","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":900,"y":540,"wires":[]},{"id":"e357ef02.ef3cb","type":"ui_group","name":"Page 1","tab":"4bc17c6e.b74934","order":2,"disp":false,"width":"6","collapse":false,"className":""},{"id":"c9165343995892c6","type":"ui_group","name":"Page 2","tab":"8f4542aa.faf2","order":1,"disp":false,"width":"6","collapse":false,"className":""},{"id":"4bc17c6e.b74934","type":"ui_tab","name":"Page 1","icon":"wi-wu-tstorms","order":5,"disabled":false,"hidden":false},{"id":"8f4542aa.faf2","type":"ui_tab","name":"Page 2","icon":"wi-wu-tstorms","order":8,"disabled":false,"hidden":false}]


image

There is no output from the ui_template

I just wanted to know if this is expected behavior or is it a bug
Regards

This code produces error in browser console so remove it.

the code i posted was not meant to be seen on the browser window for the test. I have a ui_template node in the head section that picks up the jquery to post into the browser window. If you look at the debug 5 you will see output...Debug 7 shows nothing. That is the issue. Maybe you are referring to something else?

Ok.
Passthrough is not working (at least for ui_template node) in case the msg has no payload property.
Have no time currently to test any other dashboard node

Don't know if it is bug so... @dceejay to decide

As ui nodes are meant to send things to the browser then if there is nothing to send then they save web socket bandwidth and don’t send anything (I think. Not checked code. Not near computer for a couple of weeks)

1 Like

Thanks for the reply. If I understand you correctly, if works like filter node that only passes when value changes. Since my test case the value for msg.gdx is 0 it wont update unless that message changes (.i.e. =1). That behavior would explain the inconsistent results . I was in the process of detailing a issue on github and will abort.

Regards

1 Like

Yes. Good way to think of it.

1 Like

Not actually.
The messages you are sending filtered out because there is no "payload" :
msg = { topic: 'gdx', gdx: 0, color: '#808080', }

To get them pass, just add the payload property
msg = { payload:"something" topic: 'gdx', gdx: 0, color: '#808080', }

Or rename the gdx property to payload
msg = { payload:0 topic: 'gdx', color: '#808080', }

1 Like

Thanks.. Well I am confused now, if the payload is always 0 and the message does not change, then the ui_template should not forward. I will give that a shot and test

regards

You are correct. So if you use non payload messages and want the ui_template node to pass the data, then you have to add a payload.

Thanks a lot. Sorry about the earlier confusion.

@dceejay this is still an issue,
The check box says Pass through messages from input. not pass through msg from input if there is a payload very confusing.
So if checked all messages should be passed if there is a payload or not.

It’s a scope creep over time issue. Originally most ui nodes don't pass through data, and only the payload was of use. Over time folk started to want to preserve other properties so they could tell if it was a pass thru or user action , and then indeed the template is a special case in that it always needed whatever input just in case. ( even if the payload hadn’t changed ) as who knows what the user code in the template may need to do. So yes it’s evolved and isn’t clear cut. Really the label should change to match reality as I would still resist wanting to send potentially massive objects to the browser if not needed.

Is the pass through message of ui-template being sent to browser?