# Writing to Tags

**URL:** <https://forum.inductiveautomation.com/t/writing-to-tags/77535>\
**Category:** Ignition\
**Tags:** ignition81, vision, scripting\
**Created:** [August 7, 2023, 6:46pm UTC](https://forum.inductiveautomation.com/t/writing-to-tags/77535 "2023-08-07T18:46:06Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![cole.young34](https://avatars.discourse-cdn.com/v4/letter/c/ee59a6/32.png) [@cole.young34](https://forum.inductiveautomation.com/u/cole.young34)\
**Post date:** [August 7, 2023, 6:46pm UTC](https://forum.inductiveautomation.com/t/writing-to-tags/77535/1 "2023-08-07T18:46:06Z")

</div>

Hi. I am trying to write from a list of tags and write to another list. Here is the code I am using:

```auto
paths = [
	"[ABC]Building 4/PCP/Remote Sites Bridge/Location1/Bridge_Location1_0_",
	"[ABC]Building 4/PCP/Remote Sites Bridge/Location1/Bridge_Location1_1_"
	]
	
	
values = [
	"[Remote Sites]Location1/Tank 1",
	"[Remote Sites]Location1/Tank 2"
	]
	
system.tag.writeBlocking(paths, values)

```

When using that I get the following error  
[Error\_TypeConversion("Error trying to coerce '[Remote Sites]Location1/Tank 1' to a number."), Error\_TypeConversion("Error trying to coerce '[Remote Sites]Location1/Tank 2' to a number.")]

I have also tried:

```auto
paths = [
	"[ABC]Building 4/PCP/Remote Sites Bridge/Location1/Bridge_Location1_0_",
	"[ABC]Building 4/PCP/Remote Sites Bridge/Location1/Bridge_Location1_1_"
	]
	
	
values = [
	"[Remote Sites]Location1/Tank 1".value,
	"[Remote Sites]Location1/Tank 2".value
	]
	
system.tag.writeBlocking(paths, values)

```

That returns this error:Traceback (most recent call last):  
File "", line 7, in   
AttributeError: 'str' object has no attribute 'value'

````auto
paths = [
	"[ABC]Building 4/PCP/Remote Sites Bridge/Location1/Bridge_Location1_0_",
	"[ABC]Building 4/PCP/Remote Sites Bridge/Location1/Bridge_Location1_1_"
	]
	
	
values = [
	"[Remote Sites]Location1/Tank 1".valueCurrent.value,
	"[Remote Sites]Location1/Tank 2".valueCurrent.value
	]
	
system.tag.writeBlocking(paths, values)```

````

That also gave me an error.

I am sure I am making a stupid mistake, I just don't know what it is and I have been at this way longer than I should have been.  
Thanks

---

<div class="post-metadata">

**Author:** ![kyler.kamyszek](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@kyler.kamyszek](https://forum.inductiveautomation.com/u/kyler.kamyszek)\
**Post date:** [August 7, 2023, 6:48pm UTC](https://forum.inductiveautomation.com/t/writing-to-tags/77535/2 "2023-08-07T18:48:21Z")

</div>

You need to first read the [Remote Sites] tags and put them into a variable.

tags = system.tag.readBlocking(remoteSitesPaths)

Then you can write those values to your tags. tags[0].value, tag[1].value, etc.

What you're doing is just writing a string to a tag that is probably a real/int.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [August 7, 2023, 7:09pm UTC](https://forum.inductiveautomation.com/t/writing-to-tags/77535/3 "2023-08-07T19:09:05Z")

</div>

Something like

```auto
#paths to tags to be written
write_paths = [
	"[ABC]Building 4/PCP/Remote Sites Bridge/Location1/Bridge_Location1_0_",
	"[ABC]Building 4/PCP/Remote Sites Bridge/Location1/Bridge_Location1_1_"
	]
	
#path to tags to be read
read_paths = [
	"[Remote Sites]Location1/Tank 1",
	"[Remote Sites]Location1/Tank 2"
	]

#read tags
read_Qvalues = system.tag.readBlocking(read_paths)

#get value from qualified values (optional)
read_values = [Qvalue.value for Qvalue in read_Qvalues]

#write values to tags
system.tag.writeBlocking(write_paths, read_values)

#write values to tags (if values are not extracted from the qualified values)
#system.tag.writeBlocking(write_paths, read_Qvalues)

```

---

<div class="post-metadata">

**Author:** ![cole.young34](https://avatars.discourse-cdn.com/v4/letter/c/ee59a6/32.png) [@cole.young34](https://forum.inductiveautomation.com/u/cole.young34)\
**Post date:** [August 7, 2023, 7:26pm UTC](https://forum.inductiveautomation.com/t/writing-to-tags/77535/4 "2023-08-07T19:26:48Z")

</div>

kyler.kamyszek and amarks

Thank You. I got it working, but I am not sure why mine didn't. Maybe my head is up my a&& today.

Following the code in the manual:

```auto
# Create a List of Tag Paths to write to
paths = ["Scripting/Tags/Alarm_Setpoint_1", "Scripting/Tags/Alarm_Setpoint_2"]
 
# Create a List of values to write
values = [72, 72]
 
# Send of the write requests
system.tag.writeBlocking(paths, values)

```

I assumed that if I used the

`"[Remote Sites]Location1/Tank 1"`  
or  
`"[Remote Sites]Location1/Tank 1".value`  
or  
`"[Remote Sites]Location1/Tank 1".valueCurrent.value`  
one of them would have returned the value.

Once again, thanks for you help

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [August 7, 2023, 7:31pm UTC](https://forum.inductiveautomation.com/t/writing-to-tags/77535/5 "2023-08-07T19:31:15Z")

</div>

````auto
paths = [
	"[ABC]Building 4/PCP/Remote Sites Bridge/Location1/Bridge_Location1_0_",
	"[ABC]Building 4/PCP/Remote Sites Bridge/Location1/Bridge_Location1_1_"
	]
	
	
values = [
	"[Remote Sites]Location1/Tank 1".valueCurrent.value,
	"[Remote Sites]Location1/Tank 2".valueCurrent.value
	]
	
system.tag.writeBlocking(paths, values)```

````

I would expect this line

```auto
"[Remote Sites]Location1/Tank 2".valueCurrent.value

```

to throw an error as a "[Remote Sites]Location1/Tank 2" is just a string and would have no attribute "valueCurrent.value"

\*\*edit: that's exactly the error it produced

Your issue is that "[Remote Sites]Location1/Tank 2" has nothing to do with a tag. Python has no idea what a tag is. You have to use `system.tag.readBlocking()` to get the value of a tag. To Pyhton, that's just a string. Same as any other string.

> [@cole.young34](#):
>
> kyler.kamyszek and amarks
> 
> Thank You. I got it working, but I am not sure why mine didn't. Maybe my head is up my a&& today.
> 
> Following the code in the manual:
> 
> ```auto
> # Create a List of Tag Paths to write to
> paths = ["Scripting/Tags/Alarm_Setpoint_1", "Scripting/Tags/Alarm_Setpoint_2"]
>  
> # Create a List of values to write
> values = [72, 72]
>  
> # Send of the write requests
> system.tag.writeBlocking(paths, values)
> 
> ```

With this code you will always be writing the value 72 to those 2 tags. If your goal is to write the value of 2 other tags to these tags you'll need to read those first and then use those read values in your `values` list.

---

<div class="post-metadata">

**Author:** ![cole.young34](https://avatars.discourse-cdn.com/v4/letter/c/ee59a6/32.png) [@cole.young34](https://forum.inductiveautomation.com/u/cole.young34)\
**Post date:** [August 7, 2023, 7:46pm UTC](https://forum.inductiveautomation.com/t/writing-to-tags/77535/6 "2023-08-07T19:46:13Z")

</div>

Thank you for the explanation. It is appreciated. It's making sense now......  
Now on to Google'n the "for....in" that you used so I understand just how that works....

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [August 7, 2023, 7:50pm UTC](https://forum.inductiveautomation.com/t/writing-to-tags/77535/7 "2023-08-07T19:50:33Z")

</div>

List comprehension in Pyhton.

basically this:

```auto
read_Qvalues = system.tag.readBlocking(read_paths)

read_values = []
for Qvalue in read_Qvalues:
    read_values.append(Qvalue.value)

```

becomes this:

```auto
read_Qvalues = system.tag.readBlocking(read_paths)

read_values = [Qvalue.value for Qvalue in read_Qvalues]

```

It just creates the list and assigns it all on one line. I've used chat gpt quite a bit to help me rewrite my loops into list comprehension and it's helped me understand how it works. It's not terrible to read, but it does take some practice to be able to write it from scratch.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 7, 2023, 7:52pm UTC](https://forum.inductiveautomation.com/t/writing-to-tags/77535/8 "2023-08-07T19:52:03Z")

</div>

Or just to be really pedantic

```auto
read_Values = [Qvalue.value for Qvalue in system.tag.readBlocking(readPaths)]

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 7, 2023, 7:52pm UTC](https://forum.inductiveautomation.com/t/writing-to-tags/77535/9 "2023-08-07T19:52:04Z")

</div>

You don't need to extract the values, `system.tag.write*` functions can take a list of qualified values.

> [@cole.young34](#):
>
> Hi. I am trying to write from a list of tags and write to another list. Here is the code I am using:

What is the trigger of this tag write ?  
If you just want to copy the values from one tag to another, you could use a reference tag and get rid of all scripting.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [August 7, 2023, 7:52pm UTC](https://forum.inductiveautomation.com/t/writing-to-tags/77535/10 "2023-08-07T19:52:56Z")

</div>

> [@pascal.fragnoud](#):
>
> You don't need to extract the values, `system.tag.write*` functions can take a list of qualified values.

Was not aware of that. That simplifies the script a bit.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 7, 2023, 7:53pm UTC](https://forum.inductiveautomation.com/t/writing-to-tags/77535/11 "2023-08-07T19:53:58Z")

</div>

You can force a tag quality with this.

---

<div class="post-metadata">

**Author:** ![cole.young34](https://avatars.discourse-cdn.com/v4/letter/c/ee59a6/32.png) [@cole.young34](https://forum.inductiveautomation.com/u/cole.young34)\
**Post date:** [August 7, 2023, 7:56pm UTC](https://forum.inductiveautomation.com/t/writing-to-tags/77535/12 "2023-08-07T19:56:26Z")

</div>

> [@pascal.fragnoud](#):
>
> What is the trigger of this tag write ?

I am using it in a Gateway Event Timer Script

More of less, I need to copy the value from some MQTT tags into a PLC that is connected to two different networks.... (don't ask. Corporate IT overlords.....)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 7, 2023, 7:57pm UTC](https://forum.inductiveautomation.com/t/writing-to-tags/77535/13 "2023-08-07T19:57:47Z")

</div>

Then unless the timer has any kind of importance, or the destination tags need to stay memory tags because reasons, get rid of the event script and use reference tags.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 7, 2023, 8:00pm UTC](https://forum.inductiveautomation.com/t/writing-to-tags/77535/14 "2023-08-07T20:00:09Z")

</div>

It's also possible to do a tag -\> tag sync via transaction groups, if you want another way to avoid scripting. If the end result doesn't need to be a memory tag though, definitely reference tags are the way to go.
