Property value where other property value is equal to

Hi,
I have a function node that outputs the following payload:

[[{"_id":"5f93de2accd2af06b412924d","site_id":"7f93dj27mmd2af06b7624231","name":"All","forward":"all","attr_hidden_id":"All","attr_hidden":true,"attr_no_delete":true,"attr_no_edit":true},{"_id":"5f93de2accd2af06b412924e","site_id":"7f93dj27mmd2af06b7624231","name":"Disabled","forward":"disabled","attr_hidden_id":"Disabled","attr_hidden":true,"attr_no_delete":true,"attr_no_edit":true},{"_id":"5f93de2accd2af06b412924f","site_id":"7f93dj27mmd2af06b7624231","name":"LAN","forward":"native","native_networkconf_id":"5f93de1accd8afy6g4129745","attr_hidden_id":"LAN","attr_hidden":true,"attr_no_delete":true,"attr_no_edit":true},{"_id":"5f93e137ccd2af06b4129283","site_id":"7f93dj27mmd2af06b7624231","name":"Primary Wireless","forward":"native","isolation":false,"native_networkconf_id":"8f93ed37ccd2an06b4129251","attr_no_edit":true},{"_id":"5f93e67accd2af06b41292cc","site_id":"7f93dj27mmd2af06b7624231","name":"IoT","forward":"native","isolation":false,"native_networkconf_id":"1f73p66aicd2hf06b41292c5","attr_no_edit":true},{"_id":"5f952367ccd2af06b412e782","site_id":"7f93dj27mmd2af06b7624231","name":"Guest","forward":"native","isolation":true,"native_networkconf_id":"4f95y363ccd2tf06bj12o785","attr_no_edit":true}]]

I need to obtain a property value, where the value of another property(within the same object id) is equal to a certain value.
In this case, I want to obtain the "_id" property value, where the "name" is equal to "Disabled", which should yield "5f93de2accd2af06b412924e".
I am not sure where to start; any help would be greatly appreciated.

[{"id":"9412ea51.b6d58","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[[{\"_id\":\"5f93de2accd2af06b412924d\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"All\",\"forward\":\"all\",\"attr_hidden_id\":\"All\",\"attr_hidden\":true,\"attr_no_delete\":true,\"attr_no_edit\":true},{\"_id\":\"5f93de2accd2af06b412924e\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"Disabled\",\"forward\":\"disabled\",\"attr_hidden_id\":\"Disabled\",\"attr_hidden\":true,\"attr_no_delete\":true,\"attr_no_edit\":true},{\"_id\":\"5f93de2accd2af06b412924f\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"LAN\",\"forward\":\"native\",\"native_networkconf_id\":\"5f93de1accd8afy6g4129745\",\"attr_hidden_id\":\"LAN\",\"attr_hidden\":true,\"attr_no_delete\":true,\"attr_no_edit\":true},{\"_id\":\"5f93e137ccd2af06b4129283\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"Primary Wireless\",\"forward\":\"native\",\"isolation\":false,\"native_networkconf_id\":\"8f93ed37ccd2an06b4129251\",\"attr_no_edit\":true},{\"_id\":\"5f93e67accd2af06b41292cc\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"IoT\",\"forward\":\"native\",\"isolation\":false,\"native_networkconf_id\":\"1f73p66aicd2hf06b41292c5\",\"attr_no_edit\":true},{\"_id\":\"5f952367ccd2af06b412e782\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"Guest\",\"forward\":\"native\",\"isolation\":true,\"native_networkconf_id\":\"4f95y363ccd2tf06bj12o785\",\"attr_no_edit\":true}]]","payloadType":"json","x":260,"y":2880,"wires":[["5063c216.dc483c"]]},{"id":"5063c216.dc483c","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0][name=\"Disabled\"]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":2880,"wires":[["3595022e.7ce3f6"]]},{"id":"3595022e.7ce3f6","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":780,"y":2880,"wires":[]}]

You can use Jsonata to return the object you require.

or the direct value

[{"id":"9412ea51.b6d58","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[[{\"_id\":\"5f93de2accd2af06b412924d\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"All\",\"forward\":\"all\",\"attr_hidden_id\":\"All\",\"attr_hidden\":true,\"attr_no_delete\":true,\"attr_no_edit\":true},{\"_id\":\"5f93de2accd2af06b412924e\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"Disabled\",\"forward\":\"disabled\",\"attr_hidden_id\":\"Disabled\",\"attr_hidden\":true,\"attr_no_delete\":true,\"attr_no_edit\":true},{\"_id\":\"5f93de2accd2af06b412924f\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"LAN\",\"forward\":\"native\",\"native_networkconf_id\":\"5f93de1accd8afy6g4129745\",\"attr_hidden_id\":\"LAN\",\"attr_hidden\":true,\"attr_no_delete\":true,\"attr_no_edit\":true},{\"_id\":\"5f93e137ccd2af06b4129283\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"Primary Wireless\",\"forward\":\"native\",\"isolation\":false,\"native_networkconf_id\":\"8f93ed37ccd2an06b4129251\",\"attr_no_edit\":true},{\"_id\":\"5f93e67accd2af06b41292cc\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"IoT\",\"forward\":\"native\",\"isolation\":false,\"native_networkconf_id\":\"1f73p66aicd2hf06b41292c5\",\"attr_no_edit\":true},{\"_id\":\"5f952367ccd2af06b412e782\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"Guest\",\"forward\":\"native\",\"isolation\":true,\"native_networkconf_id\":\"4f95y363ccd2tf06bj12o785\",\"attr_no_edit\":true}]]","payloadType":"json","x":260,"y":2880,"wires":[["5063c216.dc483c"]]},{"id":"5063c216.dc483c","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0][name=\"Disabled\"]._id","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":2880,"wires":[["3595022e.7ce3f6"]]},{"id":"3595022e.7ce3f6","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":780,"y":2880,"wires":[]}]
1 Like

Perfect! Just what I needed.
Thanks so much @E1cid

Is it possible to use a flow variable instead of a constant string?
Like instead of using:

[name="Disabled"]._id

Use:

[name=varname]._id

I tried several ways, but it is obvious that I am at subzero coding level.

sure

[{"id":"9412ea51.b6d58","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Disabled","payload":"[[{\"_id\":\"5f93de2accd2af06b412924d\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"All\",\"forward\":\"all\",\"attr_hidden_id\":\"All\",\"attr_hidden\":true,\"attr_no_delete\":true,\"attr_no_edit\":true},{\"_id\":\"5f93de2accd2af06b412924e\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"Disabled\",\"forward\":\"disabled\",\"attr_hidden_id\":\"Disabled\",\"attr_hidden\":true,\"attr_no_delete\":true,\"attr_no_edit\":true},{\"_id\":\"5f93de2accd2af06b412924f\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"LAN\",\"forward\":\"native\",\"native_networkconf_id\":\"5f93de1accd8afy6g4129745\",\"attr_hidden_id\":\"LAN\",\"attr_hidden\":true,\"attr_no_delete\":true,\"attr_no_edit\":true},{\"_id\":\"5f93e137ccd2af06b4129283\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"Primary Wireless\",\"forward\":\"native\",\"isolation\":false,\"native_networkconf_id\":\"8f93ed37ccd2an06b4129251\",\"attr_no_edit\":true},{\"_id\":\"5f93e67accd2af06b41292cc\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"IoT\",\"forward\":\"native\",\"isolation\":false,\"native_networkconf_id\":\"1f73p66aicd2hf06b41292c5\",\"attr_no_edit\":true},{\"_id\":\"5f952367ccd2af06b412e782\",\"site_id\":\"7f93dj27mmd2af06b7624231\",\"name\":\"Guest\",\"forward\":\"native\",\"isolation\":true,\"native_networkconf_id\":\"4f95y363ccd2tf06bj12o785\",\"attr_no_edit\":true}]]","payloadType":"json","x":260,"y":2880,"wires":[["5063c216.dc483c"]]},{"id":"5063c216.dc483c","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"($topic := topic;\tpayload[0][name=$topic]._id)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":2860,"wires":[["3595022e.7ce3f6"]]},{"id":"3595022e.7ce3f6","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":780,"y":2880,"wires":[]}]

This relies on topic. What I have is a flow variable called state.
I ended up using the following:

payload[0][name=$flowContext("state")]._id

This seems to work fine.
Thanks for your help.

You said flow variable, i took that for any flow variable/msg part. Glad you got the answer any way.

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