Hi, we are trying to make a SubFlow and we need help.
This is the desired outcome below;
ns=3;s="DB_HMI"."Rooms"[0]."Cmd"."ModuleStop"
But whatever we do in our subflow, we cannot get the brackets to work.
ns=3;s=DB_HMI.Rooms[0].Cmd.ModuleStop
var n = env.get("Room_Nr")
var ns = "ns=3;s="
var db1 = "DB_HMI";
var db2 = ".Rooms[";
var db3 = "].Cmd.";
var var1 = "ModuleStop";
node.send({"topic": ns + db1 + db2 + n + db3 + var1,"BrowseName":var1, "Room":n})
// desired = "topic":ns=3;s="DB_HMI"."Rooms"[0]."Cmd"."ModuleStop"
Any ideas to get us started?
jbudd
12 February 2022 06:46
2
Does this work? I didn't make an effort to wrap topic in quotes, don't think that's needed in Json?
var n = env.get("Room_Nr")
var ns = "ns=3;s="
var db1 = "DB_HMI";
var db2 = "Rooms";
var db3 = "Cmd";
var var1 = "ModuleStop";
const q = '"';
const qdotq = '"."';
node.send({ "topic": ns + q + db1 + qdotq + db2 + q + '[' + n + '].' + q + db3 + qdotq + var1 + q, "BrowseName": var1, "Room": `n` })
// desired = "topic":ns=3;s="DB_HMI"."Rooms"[0]."Cmd"."ModuleStop"
// gives ns=3;s="DB_HMI"."Rooms"[4]."Cmd"."ModuleStop"
return;
I think I've seen backticks used to construct this kind of output too but I don't know the syntax.
Colin
12 February 2022 11:17
5
That method maybe isn't particularly helpful in this case, as it gets a bit conjested. It can be very useful in many other circustances, particularly where quotes and so are required.
node.send({
"topic": `${ns}${q}${db1}${qdotq}${db2}${q}[${n}].${q}${db3}${qdotq}${var1}${}`,
BrowseName: var1,
Room: `n`
})
1 Like
jbudd
12 February 2022 11:31
6
It's not so bad (much better!) if you get rid of my var q and qdotq though, thanks for the example
node.send({topic: `${ns}"${db1}"."${db2}"[${n}]."${db3}"."${var1}"`, "BrowseName": var1, "Room": `n` })
1 Like
Colin
12 February 2022 11:47
7
I hadn't looked at the code to see what they are. Yes it is better I think. It is just a pity that ${}
is fiddly to type.
Works like a charm. I am going to use this from now on.
I am using excel for the bulk of code, so i dont mind the fiddly bit. Thanks you both!
system
Closed
26 February 2022 23:43
9
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.