Flow.get syntax

hello,
can someone help me with the flow.get syntax.

var shd = flow.get('schedule_G2','groupID.G2.shd_12.ontopic');
msg.payload=shd;
return msg;

image
I only want to read this one value and I am desperate because I always get everything and not dedicated ontopic from shed_12.
THX

I think this should do it:

var shd = flow.get('schedule_G2.shd_12.ontopic')

NOT SEE THE FOREST FOR THE TREES

THX

or

var shd = flow.get('schedule_G2').shd_12.ontopic;
msg.payload=shd;
return msg;

Which is faster, but unless using large objects will be unnoticable.

hello
in order to optimise my code a little more and consolidate individual functions, I am wondering whether it is possible to include 12 as a variable in var shd = flow.get('schedule_G2.shd_12.ontopic')
I have been trying with trial and error to figure out how to include the variable so that the flow get call still works.
Is it possible that I can't do it directly in the call?
THX

in a function...

var num = 12; // or 13 or msg.number or whatever!
var path = `schedule_G2.shd_${num}.ontopic`;
msg.payload = flow.get(path);
return msg;

learned something new again.
THX

As a beginner, may I ask one more question
I have seen that it does not work with ' ' but only with *
What are these called so I can search for them to understand the difference.
I have not worked with them before

  • i can't even use these characters in the forum

just escape them on forum
to show `
use \`

AHH OK. I am using a qwertz German keyboard
image

:wink: \ `

Template_literals

1 Like

Thank you - i have two more questions:

  1. work this syntax for global.get too?
  2. can we use this syntax for the SET command too?

BR
Hubertus

Yes, same syntax works for all types of context and both get/set

1 Like

Perfect! Thank you.

Once more: is the context protected against competing write access?

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