Copy tag value to another tag on third tag change

I’ve tried with system.tag.write(“tag 1”, “tag 2”) and it doesn’t work. Tried scripting (tag change - value change, global script on tag change)… can’t get it to work…

Both tags are Integers, trying to copy the value from query tag to memory tag.

What am I missing?

That’s not how system.tag.write() works. You have to supply a tag path to write to and also a value to write to that path.

Have a look at the documentation system.tag.write.

And there’s no script function that will copy values from one tag to another. You must read, then write.

Got it… I just read the second tag to a temp variable and then wrote that variable into the first tag.Worked like a charm. Thanks

Thanks for your help. I got the script working but only once and never again. I tried everything and it just won't copy the value into the new tag again.

This is what I have, a tag which is changing from 0 to 1 twice per day (1 for a minute and then goes back to zero).

In that tag I selected Tag Events > Value Changed and added this script:

if currentValue==1:
	temp = system.tag.read("[.]RT1/PcsBuilt")
	system.tag.write("[.]RT1/OS_Built", temp)

It doesn't work if I use relative paths to tags and I also tried absolute and it still doesn't work. The tag OS_Built just stays at zero and I can see the trigger tag change from 0 to 1.

Any ideas?

Edit: The trigger tag is an expression, the source tag is an SQL Query (Integer) and the destination is a memory tag (Integer), if it matters.

system.tag.read() returns a Qualified Value, containing the actual tag value in its value property, plus quality code and timestamp. You need to use temp.value in your write() operation. See the manual for more details.

Thanks, that did the trick. I also had to use currentValue.value.

1 Like

How about a sample of the correct code?

Using the example above the complete script would be:

if currentValue.value==1:
	temp = system.tag.read("[.]RT1/PcsBuilt")
	system.tag.write("[.]RT1/OS_Built", temp.value)
1 Like

As a quick aside you can also put the “.value” on the tag read itself.
Useful if you intend to use the temp variable multiple times in the same script.

if currentValue.value==1:
      temp = system.tag.read("[.]RT1/PcsBuilt").value
      system.tag.write("[.]RT1/OS_Built", temp)
1 Like