# Writing to a tag with scripting

**URL:** <https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694>\
**Category:** Ignition\
**Created:** [April 21, 2022, 2:16pm UTC](https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694 "2022-04-21T14:16:27Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [April 21, 2022, 2:16pm UTC](https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694/1 "2022-04-21T14:16:27Z")

</div>

I need help in scripting, I need to write the status of one tag to another. Here is what I have so far and it doesnt work. What am I missing? I am using 8.1.0

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/9/790c315f30fcd243c7fa9250330273feab122ce1.png)

---

<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:** [April 21, 2022, 2:24pm UTC](https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694/2 "2022-04-21T14:24:32Z")

</div>

Context is important.

1.) Generally post the script using the preformatted text option, so that we can copy and paste your code into our posts to help you.

2.) You’ve clipped some rather important information out of your screen shot.

I see “event” in the doc string, but I don’t know what kind of event it is.

I also see `value=currentValue` so I’m **assuming** this is probably a tag event script. So here is my best guess as to what the real issue is, currentValue is a _ **qualifiedValue** _ object. You have to pull the actual value out of it.

Also, since this is Version 8.1, you should be using `system.tag.writeBlocking()`

Try this:

```auto
path = '[.]Tilter_Alarm/Siren_Alarm'
value = currentValue.value
system.tag.writeBlocking([path],value)

```

Or If you would all you really need is this:

```auto
system.tag.writeBlocking(['[.]Tilter_Alarm/Siren_Alarm'],currentValue.value)

```

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [April 21, 2022, 2:28pm UTC](https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694/3 "2022-04-21T14:28:11Z")

</div>

here is the code. also i am trying to write the status of a boolean to another boolean, so when its true the other bool is true also.

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	"""
	Fired whenever the current value changes in value or quality.

	Arguments:
		tag: The source tag object. A read-only wrapper for obtaining tag
		     properties.
		tagPath: The full path to the tag (String)
		previousValue: The previous value. This is a "qualified value", so it
		               has value, quality, and timestamp properties.
		currentValue: The current value. This is a "qualified value", so it has
		              value, quality, and timestamp properties.
		initialChange: A boolean flag indicating whether this event is due to
		               the first execution or initial subscription.
		missedEvents: A flag indicating that some events have been skipped due
		              to event overflow.
	"""
	path="[.]Tilter_Alarm/Siren_Alarm.value]"
	value=currentValue
	system.tag.write(path, value)

```

---

<div class="post-metadata">

**Author:** ![peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@peter](https://forum.inductiveautomation.com/u/peter)\
**Post date:** [April 21, 2022, 2:29pm UTC](https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694/4 "2022-04-21T14:29:28Z")

</div>

There seems to be a couple of issues:

1. You do not need the “.value” in the path
2. Your path string has an extra “]” at the end

Also, when posting code, it’s preferable to post the text and not an image of the text.

Finally, at some point system.tag.write was deprecated, but I am not sure in what version. Ideally you should be using system.tag.readBlocking and system.tag.writeBlocking instead of system.tag.read and system.tag.write

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [April 21, 2022, 2:52pm UTC](https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694/5 "2022-04-21T14:52:56Z")

</div>

I have tried both:

```auto
	path = '[.]Tilter_Alarm/Siren_Alarm'
	value = currentValue.value
	system.tag.writeBlocking([path],value)

```

and

```auto
system.tag.writeBlocking(['[.]Tilter_Alarm/Siren_Alarm'],currentValue.value)

```

Nether is resulting in when one bool is true the other is also true.  
I apologize in advance for my ignorance

---

<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:** [April 21, 2022, 2:57pm UTC](https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694/6 "2022-04-21T14:57:30Z")

</div>

Are both of these OPC tags?

Have you considered using an Expression Tag, or a Derived Tag?

There is nothing incorrect with the code as I have written it, so it should work. That leaves only an incorrect path as the culprit.

How did you get the tag path?

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [April 21, 2022, 3:04pm UTC](https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694/7 "2022-04-21T15:04:52Z")

</div>

the tag doing the write is a memory tag for test purposes, but will come from and OPC bool tag. The OPC bool tag is our plants weather alarms. The tag receiving the write is a bool that will sound an alarm in another part of our plant. the tag path was acquired by the tag icon in the top RH corner of the scripting pop-up.

---

<div class="post-metadata">

**Author:** ![peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@peter](https://forum.inductiveautomation.com/u/peter)\
**Post date:** [April 21, 2022, 3:08pm UTC](https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694/8 "2022-04-21T15:08:50Z")

</div>

> system.tag.writeBlocking([path],value)

Is incorrect. In the [writeBlocking](https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking) version of the function, both the paths and the values are Python [lists](https://www.w3schools.com/python/python_lists.asp). So the correct call should be:

> system.tag.writeBlocking([path],[value])

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [April 21, 2022, 3:10pm UTC](https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694/9 "2022-04-21T15:10:33Z")

</div>

> [@mjohnson0238](#):
>
> `system.tag.writeBlocking(['[.]Tilter_Alarm/Siren_Alarm'],currentValue.value)`

[should be](https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking):

```auto
system.tag.writeBlocking(['[.]Tilter_Alarm/Siren_Alarm'],[currentValue.value])

```

Also, you can look at the log on the Gateway web page to see if there are any warnings/errors...

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [April 21, 2022, 3:27pm UTC](https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694/10 "2022-04-21T15:27:30Z")

</div>

I can get the above to write from a memory tag to another memory tag, but not to an OPC bool tag. Can an OPC bool only be written to by another OPC bool tag?

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [April 21, 2022, 3:29pm UTC](https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694/11 "2022-04-21T15:29:43Z")

</div>

Nevermind that guys, not sure what I just did but I just got the memory tag to write to the bool tag

---

<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:** [April 21, 2022, 3:31pm UTC](https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694/12 "2022-04-21T15:31:40Z")

</div>

Oh boy, open mouth insert foot. 🤦‍♂️

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [April 21, 2022, 3:37pm UTC](https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694/13 "2022-04-21T15:37:44Z")

</div>

Oh well, I say “if you aint ever wrong, you aint learning”. lol

---

<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:** [April 21, 2022, 3:49pm UTC](https://forum.inductiveautomation.com/t/writing-to-a-tag-with-scripting/58694/14 "2022-04-21T15:49:01Z")

</div>

You really should mark @peter 's response as the solution, since he actually posted the correct code. That will help future readers the most.
