I have two global variables: global.mac = "E4:5F:01:FE:DC:BA"
and global.macvendors = {
"E8:48:B8":"TP-Link",
"E4:5F:01":"Raspberry Pi",
"5C:CF:7F":"Espressif",
"D8:49:2F":"Canon"
}
So the vendor bit of mac is $substring($globalContext("mac"), 0, 8) or "E4:5F:01"
And the vendor is $globalContext("macvendors")."E4:5F:01" or "Raspberry Pi"
But I can't work out how to combine the two into a single command to get "Raspberry Pi" $globalContext("macvendors").$substring($globalContext("mac"), 0, 8) is valid JSONata but confusingly it returns the mac address substring "E4:5F:01"
How should I do this?
Is macvendors structured properly or should it be an array?
Yes, many of mine now allow its use as well - though it is a pain to accommodate since it is async. I must admit that I've started using it a bit more since then as it is a great way to quickly add some dynamic processing to a field. Annoying though when you realise that you imagined seeing $sin and $tan functions in the list!
Yup, Marcus' $lookup works.
But why can I use
$globalContext("macvendors").string but not
$globalContext("macvendors").$function?
I think Julian's is a multi-line equivalent of my attempt.
I had attempted := (Pascal!) and ; but they were rejected.
Seems like the brackets round the whole lot are important.
I would agree - its a little odd.
its a love/hate relationship - I do like to use it in the right situation, but its a little odd in behaviour at times
It doesn't like variables either, that's why your expression returned the substring of the mac. The issue is the dot has two meanings, one the path notation, and two the mapping function. I think that is why they have lookup() rather than [ ].
OK "macvenddors." & $substring($globalContext("mac"), 0, 8) is concatenation so this is $globalContext("macvendors.E4:5F:01")
And indeed similar (javascript) syntax in a function node: msg.payload = global.get("macvendors.E4:5F:01") works (who knew?)
"with no JSONata" wow, surprised to see that
Thanks for the suggestions everyone, lots of food for thought there.