Another lookup but this time with text

I really don't like having this many things happening, but ..... needs must.

This is the structure:


If it isn't obvious what I want to do:

I want to send (eg) abccomedy and get back 152.

Numbers are easy-er to do, as I guess it just searches mathematically.
Or more so: It looks at the n'th entry.

I'm not sure text is done in the same way.

(This is probably too easy, but please......)

How is it done?

Thanks in advance.

Ok, I worked it out.

That's in a function node defined as:

var channels =

Then the table.

At the bottom of the table:


let x = channels[msg.payload];

msg.payload = x.number;

Inject abccomedy get out 152.

I can post the entire node contents if desired for clarity. But it is pretty much in the first post.

(ah! Here is the whole flow. All 3 nodes!)


The flow I posted doesn't have that bit of code at the end.
I goofed and found the problem.

Really putting the {"number": is a bit silly.

[{"id":"2bc0b7ba.625f78","type":"inject","z":"703c61ac.837e1","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"abccomedy","payloadType":"str","x":280,"y":2550,"wires":[["18735c11.1bf75c"]]},{"id":"18735c11.1bf75c","type":"function","z":"703c61ac.837e1","name":"","func":"var channels = {\n    \"nine\":{\"number\":100},\n    \"foxone\":{\"number\":101},\n    \"abc\":{\"number\":102},\n    \"sbs\":{\"number\":104},\n    \"uktv\":{\"number\":105},\n    \"seven\":{\"number\":107},\n    \"foxeight\":{\"number\":108},\n    \"ten\":{\"number\":110},\n    \"showcase\":{\"number\":112},\n    \"sifi\":{\"number\":116},\n    \"foxclassic\":{\"number\":117},\n    \"bbcfirst\":{\"number\":119},\n    \"universal\":{\"number\":120},\n    \"history\":{\"number\":130},\n    \"discovery\":{\"number\":133},\n    \"natgeo\":{\"number\":139},\n    \"boxsets\":{\"number\":150},\n    \"abccomedy\":{\"number\":152},\n    \"seventwo\":{\"number\":156},\n    \"sevenmate\":{\"number\":157},\n    \"sevenflix\":{\"number\":158},\n    \"ningo\":{\"number\":162},\n    \"ninegem\":{\"number\":164},\n    \"sbsviceland\":{\"number\":170},\n    \"foxone+2\":{\"number\":201},\n    \"uktv+2\":{\"number\":202},\n    \"foxeight+2\":{\"number\":208},\n    \"showcase+2\":{\"number\":212},\n    \"sifi+2\":{\"number\":216},\n    \"foxclassic+2\":{\"number\":217},\n    \"discovery+2\":{\"number\":233},\n    \"natgeo+2\":{\"number\":239},\n    \"sbsvicelandhd\":{\"number\":270}\n}\n\nmsg.payload = channels[msg.payload];\n \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":450,"y":2550,"wires":[["aee01ab5.dedee8"]]},{"id":"aee01ab5.dedee8","type":"debug","z":"703c61ac.837e1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":2550,"wires":[]}]

It is not silly. In any case you decide in future that it would be nice to hold some other parameters in that channels object. Like display name, description, favorite, or whatever such kind of stuff, you just can add it and no need to change too much around it.

1 Like


I don't know if it will ever be needed again.

Just "foxtel" decided to do a big channel change recently.
That messed up all my code as I was sending channel numbers.

This way I send the name and pass it through this node to get the number.

Then if they change them again, I only have to edit one node.

Weird they said that the channels couldn't be changed when I submitted an idea very similar to this years ago.

Interesting how things happen, huh? :wink:

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