# Copy tag value to another tag on third tag change

**URL:** <https://forum.inductiveautomation.com/t/copy-tag-value-to-another-tag-on-third-tag-change/22155>\
**Category:** Ignition\
**Created:** [January 28, 2019, 1:34pm UTC](https://forum.inductiveautomation.com/t/copy-tag-value-to-another-tag-on-third-tag-change/22155 "2019-01-28T13:34:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![damzagar](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@damzagar](https://forum.inductiveautomation.com/u/damzagar)\
**Post date:** [January 28, 2019, 1:34pm UTC](https://forum.inductiveautomation.com/t/copy-tag-value-to-another-tag-on-third-tag-change/22155/1 "2019-01-28T13:34:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [January 28, 2019, 1:42pm UTC](https://forum.inductiveautomation.com/t/copy-tag-value-to-another-tag-on-third-tag-change/22155/2 "2019-01-28T13:42:05Z")

</div>

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](https://docs.inductiveautomation.com/display/DOC79/system.tag.write).

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 28, 2019, 1:50pm UTC](https://forum.inductiveautomation.com/t/copy-tag-value-to-another-tag-on-third-tag-change/22155/3 "2019-01-28T13:50:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![damzagar](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@damzagar](https://forum.inductiveautomation.com/u/damzagar)\
**Post date:** [January 28, 2019, 2:09pm UTC](https://forum.inductiveautomation.com/t/copy-tag-value-to-another-tag-on-third-tag-change/22155/4 "2019-01-28T14:09:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![damzagar](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@damzagar](https://forum.inductiveautomation.com/u/damzagar)\
**Post date:** [January 29, 2019, 12:48pm UTC](https://forum.inductiveautomation.com/t/copy-tag-value-to-another-tag-on-third-tag-change/22155/5 "2019-01-29T12:48:21Z")

</div>

> [@pturmel](#):
>
> And there's no script function that will copy values from one tag to another. You must read, then write.

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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 29, 2019, 1:46pm UTC](https://forum.inductiveautomation.com/t/copy-tag-value-to-another-tag-on-third-tag-change/22155/6 "2019-01-29T13:46:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![damzagar](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@damzagar](https://forum.inductiveautomation.com/u/damzagar)\
**Post date:** [January 29, 2019, 3:25pm UTC](https://forum.inductiveautomation.com/t/copy-tag-value-to-another-tag-on-third-tag-change/22155/7 "2019-01-29T15:25:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![AFULLER](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/afuller/32/7931_2.png) [@AFULLER](https://forum.inductiveautomation.com/u/AFULLER)\
**Post date:** [January 8, 2020, 12:34pm UTC](https://forum.inductiveautomation.com/t/copy-tag-value-to-another-tag-on-third-tag-change/22155/8 "2020-01-08T12:34:52Z")

</div>

How about a sample of the correct code?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [January 8, 2020, 12:41pm UTC](https://forum.inductiveautomation.com/t/copy-tag-value-to-another-tag-on-third-tag-change/22155/9 "2020-01-08T12:41:56Z")

</div>

Using the example above the complete script would be:

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

```

---

<div class="post-metadata">

**Author:** ![bkthomas](https://avatars.discourse-cdn.com/v4/letter/b/7ab992/32.png) [@bkthomas](https://forum.inductiveautomation.com/u/bkthomas)\
**Post date:** [January 8, 2020, 2:24pm UTC](https://forum.inductiveautomation.com/t/copy-tag-value-to-another-tag-on-third-tag-change/22155/10 "2020-01-08T14:24:46Z")

</div>

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.

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

```
