#Property comparison weirdness

1 messages ยท Page 1 of 1 (latest)

spring apex
#

No I meant the value of the msg object from your debug output.

#

Property comparison weirdness

gentle barn
#

The msg object from your example or from my implementation? The above copy is from my implementation

spring apex
#

From yours. I know mine works.

gentle barn
#

Is that not what I have shared?

#

Sorry if that's stupid

spring apex
#

Oh. It looked like a Node Red export. Maybe I'm the stupid one ๐Ÿ˜„

gentle barn
#

Okay, amazing, that definitely works

#

I don't really understand why though...

spring apex
#

Me neither.

#

But it's definitely not because of an array.

gentle barn
#

Interesting

#

Is that function actually changing anything?

spring apex
#

But it basically replaces the whole msg with what you had so I can test it over and over again exactly as if I had your input.

gentle barn
#

I'm a little confused about what to try now, seeing as the exact same msg works from a function

#

hang on, now if I skip the function it's working

#

Sorry no ignore me

spring apex
#

I'd try without JSONata.

gentle barn
#

My message comes from a plugin node, I don't really have any control over it ๐Ÿ˜ฅ

spring apex
#

Your change node uses JSONata.

gentle barn
#

I'm not even using a change node now, it's literally this

spring apex
#

Add a whole msg debug node after the discord node. Then please share the flow and the debug's output.

gentle barn
#

Debug output:

{"_msgid":"18dee81b38c5cd3c","payload":"test","channel":{"type":0,"guild":"1226774624331890708","guildId":"1226774624331890708","permissionOverwrites":["1226774624331890708","1264841235903025183"],"messages":["1274753055379951657"],"threads":[],"nsfw":false,"flags":0,"id":"1264841748308430984","name":"bot-test","rawPosition":3,"parentId":"1226774624834949211","topic":null,"lastMessageId":"1274753055379951657","defaultThreadRateLimitPerUser":null,"rateLimitPerUser":0,"createdTimestamp":1721632172420},"member":{"guildId":"1226774624331890708","joinedTimestamp":1712556262828,"premiumSinceTimestamp":null,"nickname":null,"pending":false,"communicationDisabledUntilTimestamp":null,"userId":"130568230078119936","avatar":null,"flags":0,"displayName":"kridges","roles":["1264843949072187402","1226774624331890708"],"avatarURL":null,"displayAvatarURL":"https://cdn.discordapp.com/avatars/130568230078119936/a_c0aa28b634c496ea913824d802113590.gif"},"memberRoleNames":[{"guild":"1226774624331890708","icon":null,"unicodeEmoji":null,"id":"1264843949072187402","name":"HomeController","color":0,"hoist":false,"rawPosition":1,"permissions":"0","managed":false,"mentionable":false,"flags":0,"tags":{},"createdTimestamp":1721632697123},{"guild":"1226774624331890708","icon":null,"unicodeEmoji":null,"id":"1226774624331890708","name":"@everyone","color":0,"hoist":false,"rawPosition":0,"permissions":"2222085186637377","managed":false,"mentionable":false,"flags":0,"tags":{},"createdTimestamp":1712556262811}],"memberRoleIDs":[{"guild":"1226774624331890708","icon":null,"unicodeEmoji":null,"id":"1264843949072187402","name":"HomeController","color":0,"hoist":false,"rawPosition":1,"permissions":"0","managed":false,"mentionable":false,"flags":0,"tags":{},"createdTimestamp":1721632697123},{"guild":"1226774624331890708","icon":null,"unicodeEmoji":null,"id":"1226774624331890708","name":"@everyone","color":0,"hoist":false,"rawPosition":0,"permissions":"2222085186637377","managed":false,"mentionable":false,"flags":0,"tags":{},"createdTimestamp":1712556262811}],"data":{"channelId":"1264841748308430984","guildId":"1226774624331890708","id":"1274753055379951657","createdTimestamp":1723995212169,"type":0,"system":false,"content":"test","authorId":"130568230078119936","pinned":false,"tts":false,"nonce":"1274753055773949952","embeds":[],"components":[],"attachments":[],"stickers":[],"position":null,"roleSubscriptionData":null,"resolved":null,"editedTimestamp":null,"mentions":{"everyone":false,"users":[],"roles":[],"crosspostedChannels":[],"repliedUser":null,"members":[],"channels":[]},"webhookId":null,"groupActivityApplicationId":null,"applicationId":null,"activity":null,"flags":0,"reference":null,"interaction":null,"poll":null,"cleanContent":"test"},"author":{"id":"130568230078119936","bot":false,"system":false,"flags":0,"username":"kridges","globalName":"kridges","discriminator":"0","avatar":"a_c0aa28b634c496ea913824d802113590","banner":"a_46c8a6d2914e6f4690e7201fd99059e4","accentColor":11592959,"avatarDecoration":null,"createdTimestamp":1451200291891,"defaultAvatarURL":"https://cdn.discordapp.com/embed/avatars/1.png","hexAccentColor":"#b0e4ff","tag":"kridges","avatarURL":"https://cdn.discordapp.com/avatars/130568230078119936/a_c0aa28b634c496ea913824d802113590.gif","displayAvatarURL":"https://cdn.discordapp.com/avatars/130568230078119936/a_c0aa28b634c496ea913824d802113590.gif","bannerURL":"https://cdn.discordapp.com/banners/130568230078119936/a_46c8a6d2914e6f4690e7201fd99059e4.gif"}}
spring apex
#

My addon is 18.0.5 btw.

gentle barn
spring apex
gentle barn
#

The weird thing is I can definitely write conditions on the member.displayName value, which is obviously not within an array

#

That's why I think it's an array thing

#

Perhaps there's a special character that is not going in the function but is persisting from the discord node?

spring apex
#

Makes no sense through if my flows work fine for you and do exactly the same.

#

That was my thought and why I wanted the output.

gentle barn
#

It's gotta be something to do with the Discord node, and somehow not impacting all values

spring apex
#

Let's try something really simple then. Add this node after your discord node

[{"id":"4464cb801fe3c9f7","type":"function","z":"cae8eceb71b2cae3","name":"Check for msg.memberRoleNames[0].name","func":"node.warn(`msg.memberRoleNames[0].name: \"${msg.memberRoleNames[0].name}\"`);\n\nif (msg.memberRoleNames[0].name == \"HomeController\") {\n    node.warn(`HomeController found`);\n} else {\n    node.warn(`HomeController not found`);\n}\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":380,"wires":[[]]}]
gentle barn
#

TypeError: Cannot read properties of undefined (reading 'name')

spring apex
#

Interesting.

gentle barn
spring apex
#

Try this variant

[{"id":"58ee766f8c876f10","type":"function","z":"cae8eceb71b2cae3","name":"Check for msg.memberRoleNames[0].name","func":"node.warn(msg);\nnode.warn(`msg.memberRoleNames[0].name: \"${msg.memberRoleNames[0].name}\"`);\n\nif (msg.memberRoleNames[0].name == \"HomeController\") {\n    node.warn(`HomeController found`);\n} else {\n    node.warn(`HomeController not found`);\n}\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":710,"y":280,"wires":[[]]}]
gentle barn
spring apex
#

Can you expand the warn object.

gentle barn
#

It looks like a copy of the normal message

spring apex
#

I don't really understand what's happening here.

gentle barn
#

I'm glad I'm not the only one

#

There's clearly something going on outside of the message

spring apex
#

But maybe these tests still helped somewhat.

gentle barn
#

Is there a method to convert a whole object into a string and then try a compare on that?

#

It's almost 2am on a work night so I'm going to come back to this another time, maybe after a version upgrade. I'm not awfully hopeful that it'll change anything but you never know :D

#

Thanks for your help @spring apex , really appreciate it

spring apex
#

Not directly. It would be a mess to convert JSON to a single string, no?

#

There's a JSON node though to convert objects to JSON and JSON.stringify for the function node.

gentle barn
gentle barn
#

Clearly it's a pretty shit solution but at least now nodered can find the value I'm looking for

#

On the plus side it's potential future proofing, ensuring that it checks all items in the array, which covers me in case they change order

spring apex
#

You can do this via JSONata too with something like

[$contains(name, "HomeController")]

Not very trivial though and I already forgot most of JSONata's syntax.

gentle barn
#

Sorry for another dumb question - what node should this be in?

spring apex
#

Whatever you want. In my case I use a change node to extract it.

gentle barn
#

This is my first Nodered project so my brain is empty

spring apex
#

I use this to extract power plugs and other things from my Zigbee2MQTT's devices message.

#

It's a big hack so I can reconfigure their reporting interval which gets reset sometimes. To do this I need to extract their names and this is what I came up with since they all share a prefix.

gentle barn
#

I think that's a cleaner solution

#

One less node at least

spring apex
#

I hate that I don't know what causes this weird behavior though.