SubFlow OPCUA brackets around string

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"

image

But whatever we do in our subflow, we cannot get the brackets to work.

ns=3;s=DB_HMI.Rooms[0].Cmd.ModuleStop

image

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?

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.

Wow, you are the best. :kissing_heart:

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

It's not so bad (much better!) if you get rid of my var q and qdotq though, thanks for the example :slightly_smiling_face:

node.send({topic: `${ns}"${db1}"."${db2}"[${n}]."${db3}"."${var1}"`, "BrowseName": var1, "Room": `n` })
1 Like

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!

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