Add,edit,delete tags from one gateway and push changes to other gateway

Hi,

I am trying to create a perspective project on Data center gateway.

In that i am trying to add tag and push the new added tag to plant gateway. Where i have a tags created in default provider (In that provider i need to add the tag which i pushed)

how to do this one… can any one share your ideas please?

i suppose you will have to send a message to the other gateway with the correct payloads and there use
https://docs.inductiveautomation.com/display/DOC81/system.tag.configure

2 Likes

thanks i will check it out

I had to do something like this not long ago, I did use messages:
A message handler gateway event script that receives the data and writes it to a tag,
And a system.util.sendMessage() call on the other gateway that sends the appropriate data:

system.util.sendMessage(target_project, message_handler, payload=payload, remoteServers=[target_gateway])

Ok i will use this function… I am trying add or edit or delete a tag to a corresponding folder in another gateway

For that system.tag.configure i need to use this one.

How to link this function and your util. Message(i mean payload function)

I am trying to push my changes from one gateway to another gateway

Any example script can you able to give?

Don’t script it on the gateway that sends the message, but on the gateway that receives it.
You put it in the gateway event scripts, there’s a message section there:
image
That’s a message handler, let’s call it testHandler
In this script, you call system.tag.configure() to add your tag, or do whatever you need to do.

Now, in the sending project, when you want to call this script, you just call

target_project = <the name of the receiving project>
target_gateway = <the gateway where the receiving project is>
payload = <a dictionnary of data you want to send, can be empty>
system.util.sendMessage(target_project, 'testHandler', payload=payload, remoteServers=[target_gateway])

remoteServers needs to be a list, that why there are [] surrounding target_gateway.

And that’s it.

1 Like

One doubt how to pass this to payload like this

payload = [system.tag.configure(baseTagPath, tags, collisionPolicy)]

is it correct?

No !

You don’t pass the function, the script in the message handler already knows what to do. The payload is only data you need to PASS to system.tag.configure() or to compute its parameters.

Let’s do a concrete example.
Say you want to create a memory tag named foo, with value bar on gateway GWA, which has a project A, when a button in the project B that is on gateway GWB is clicked.

In project A, you make a message script in the gateway event scripts, and you call it addTag:

tag = payload.tag
path = payload.path
system.tag.configure(path, tag, 'o')

This is in charge of configuring a tag at path path.

Now, on the onActionPerformed event of your button, you add this:

path = "[]baz"
tag = {
	'name': "foo",
	'valueSource': "memory",
	'dataType': "String",
	'value': "bar",
	'tagType': "AtomicTag"
}
payload = {
	path: path,
	tag: tag
}
system.util.sendMessage('A', 'addTag', payload=payload, remoteServers=['GWA'])

This sends ONLY sends a message that needs to be intercepted by an handler called addTag, in project A, that lives in gateway GWA, with some data that’s conventionally called payload.

When the message is sent, the handler in project A receives it, and does whatever it was configured to do. Here, it will use the data in payload to create a tag.

Project B has no notion of writing tags or calling function, all it does is toss a bottle in the ocean, with a label on it that says this is for A ! and a piece of paper inside where the payload is written.
When A find the bottle, it opens it, reads the paper inside and does its thing. Turns out, its thing is writing tags based on papers it finds in bottles.

Now, there are ways of doing it differently. You could actually send a function name as payload, to give more specific instructions. But this gets more complicated, and you don’t need it in your case.

edit:
Adapt the above example to match your case, for example if all the tags you need to write are memory tags of type String at the same location, you could just pass the name and the value of the tag and let the handler construct the tag:
on B:

payload = {
    name: "foo"
    value: "bar"
}
system.util.sendMessage('A', 'addTag', payload=payload, remoteServers=['GWA'])

and on A:

tag = {
	'name': payload.name,
	'valueSource': "memory",
	'dataType': "String",
	'deadbandMode': "Off",
	'value': name.value,
	'tagType': "AtomicTag"
}
system.tag.configure("[]thisIsThePath", tag, 'o')
1 Like

Thanks a lot for your clear explanation. I will implement this one and check