# Tag in Event Script

**URL:** <https://forum.inductiveautomation.com/t/tag-in-event-script/70518>\
**Category:** Ignition\
**Created:** [March 2, 2023, 8:32am UTC](https://forum.inductiveautomation.com/t/tag-in-event-script/70518 "2023-03-02T08:32:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matabufalez](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matabufalez/32/42267_2.png) [@Matabufalez](https://forum.inductiveautomation.com/u/Matabufalez)\
**Post date:** [March 2, 2023, 8:32am UTC](https://forum.inductiveautomation.com/t/tag-in-event-script/70518/1 "2023-03-02T08:32:25Z")

</div>

Hi,  
I have configured an event script "onClick" with the following text:  
{[default]Tag/MyTag.value} = 123456  
but MyTag is not changing. It is so simple, what is going wrong? I want to set that value by clicking the element.  
What if I would set MyTag (memory tag) to another OPC tag on click?  
{[default]Tag/Memory.value} = {[default]Tag/OPCTag.value}

It is not working, I am not familiarized with Event Script. Thanksss!

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [March 2, 2023, 12:03pm UTC](https://forum.inductiveautomation.com/t/tag-in-event-script/70518/2 "2023-03-02T12:03:02Z")

</div>

Try this script instead:

```auto
tagPaths = ['[default]Tag/MyTag']
writeValues = [123456]
system.tag.writeBlocking(tagPaths, writeValues)

```

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [March 2, 2023, 12:32pm UTC](https://forum.inductiveautomation.com/t/tag-in-event-script/70518/3 "2023-03-02T12:32:41Z")

</div>

If it's happening what i think it's happening and the script worked, here's what's wrong:  
When you're working with **Scripts** , you don't need the "{}" arround the tag name, that's for when you're using **expressions** and you want to use a tag value as a variable.  
You can learn more about the differences here:  
[https://docs.inductiveautomation.com/display/DOC81/Scripting+Vs.+SQL+Vs.+Expressions](https://docs.inductiveautomation.com/display/DOC81/Scripting+Vs.+SQL+Vs.+Expressions)

To write to a tag using a script, you need to use the **system.tag.writeBlocking()** or the **system.tag.writeAsync** functions, and for it to work you need to pass two parameters, a list of tag paths to write to and a list of values to write for each tag path, in the script above i've named them **tagPaths** and **writeValues** respectively.  
You can learn more about these functions here:  
[https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking](https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking)

And here:  
[https://docs.inductiveautomation.com/display/DOC81/system.tag.writeasync](https://docs.inductiveautomation.com/display/DOC81/system.tag.writeasync)

For you to be able to **write** to a tag in a script you need a function, so naturally to **read** a tag value you also need a function, the functions are called **system.tag.readBlocking()** and **system.tag.readAsync()** but in this case you only need to provide a parameter with the list of tags you want to read and the function will return a **list** of **qualified** values, so in this case if you want to set your tag to another tag value, your script will look like this:

```auto
#First we get the path(s) we want to read
readTagPaths = ['[default]Tag/OPCTag.value']
#Now we read the tags in the paths list
valuesRead = system.tag.readBlocking(readTagPaths)
#After reading,the function will return a list of qualified values
#so we need to acces the first item on the list and get the .value
#of the read result
writeValues = [valuesRead[0].value]
#Now we define the path(s) of the tag(s) we want to write to
writeTagPaths = ['[default]Tag/MyTag']
#And finally, we pass the value we've read earlier as the value param
system.tag.writeBlocking(writeTagPaths, writeValues)

```

You can learn more about the functions here:  
[https://docs.inductiveautomation.com/display/DOC81/system.tag.readBlocking](https://docs.inductiveautomation.com/display/DOC81/system.tag.readBlocking)

And here:  
[https://docs.inductiveautomation.com/display/DOC81/system.tag.readasync](https://docs.inductiveautomation.com/display/DOC81/system.tag.readasync)

I would **really** recommend taking the _free_ Inductive University credential courses, especially the **Scripting in Ignition** , besides being _free_, it's a great way to learn the basics of the Ignition Platform.

> **[Inductive University Course List - Learn Ignition Free](https://www.inductiveuniversity.com/courses/ignition/scripting-in-ignition/8.1)**
>
> Learn the fundamentals and advanced features of Ignition while earning your IU credential

I hope this was helpful.
