# Tag change execute script

**URL:** <https://forum.inductiveautomation.com/t/tag-change-execute-script/65751>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting\
**Created:** [October 27, 2022, 12:08pm UTC](https://forum.inductiveautomation.com/t/tag-change-execute-script/65751 "2022-10-27T12:08:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [October 27, 2022, 12:08pm UTC](https://forum.inductiveautomation.com/t/tag-change-execute-script/65751/1 "2022-10-27T12:08:28Z")

</div>

Hello everyone.

I would like to execute a script when a Tag change value. Is this possible? If yes could someone share, if not possible, what could be the alternative?

I'm trying to execute a script in the Project Library.  
The main idea is when the tag change I would like to print a label (send the command to print). I already did the function to print, but only works if the user presses the button, I need the system to print when I have the tag changed or execute the same function as pressing the button.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 27, 2022, 12:23pm UTC](https://forum.inductiveautomation.com/t/tag-change-execute-script/65751/2 "2022-10-27T12:23:05Z")

</div>

Start here:  
[https://docs.inductiveautomation.com/display/DOC81/Tag+Event+Scripts](https://docs.inductiveautomation.com/display/DOC81/Tag+Event+Scripts)

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [October 27, 2022, 12:34pm UTC](https://forum.inductiveautomation.com/t/tag-change-execute-script/65751/3 "2022-10-27T12:34:50Z")

</div>

Sorry, I think I was not clear with my question, I will change it.  
Thanks for the answer.  
I already tried that, I'm trying to execute a script in the Project Library.  
The main idea is when the tag change I would like to print a label (send the command to print). I already did the function to print, but only works if the user presses the button, I need the system to print when I have the tag changed or execute the same function as pressing the button.

---

<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:** [October 27, 2022, 12:38pm UTC](https://forum.inductiveautomation.com/t/tag-change-execute-script/65751/4 "2022-10-27T12:38:07Z")

</div>

Also these, which have somewhat different functionality and limitations:

[Gateway Tag Change Scripts](https://docs.inductiveautomation.com/display/DOC81/Gateway+Event+Scripts#GatewayEventScripts-TagChangeScripts)

These are defined in the project, so can call scripts in the same project.

Also consider using tag binding to Perspective session/page/view custom properties, then using a [Perspective Property Change Script](https://docs.inductiveautomation.com/display/DOC80/Perspective+Property+Change+Scripts). These can also call scripts in the same project, but also have access to the User Interface components at their scope.

{ Do remember that all Perspective scripts run in the gateway, so will see printers and such from the gateway's viewpoint. If you have this working on a Perspective pushbutton, you should be fine. }

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [October 27, 2022, 12:40pm UTC](https://forum.inductiveautomation.com/t/tag-change-execute-script/65751/5 "2022-10-27T12:40:24Z")

</div>

Thanks, I will try your suggestion.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 27, 2022, 12:40pm UTC](https://forum.inductiveautomation.com/t/tag-change-execute-script/65751/6 "2022-10-27T12:40:25Z")

</div>

OK, you're trying to change a Perspective application to a gateway application (and Perspective won't be relevant anymore).

What happens when you put your button code into the tag event script?

Post your code (using the \</\> code formatting button).

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [October 27, 2022, 12:53pm UTC](https://forum.inductiveautomation.com/t/tag-change-execute-script/65751/7 "2022-10-27T12:53:05Z")

</div>

Thanks, @Transistor and @pturmel.

@pturmel , I did your suggestion. I forgot to use [Gateway Tag Change Scripts](https://docs.inductiveautomation.com/display/DOC81/Gateway+Event+Scripts#GatewayEventScripts-TagChangeScripts).

This is what I did.

```auto
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if previousValue <> currentValue:
		T320B.RecordWIP(self)

```

Thanks, again everyone.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 27, 2022, 4:15pm UTC](https://forum.inductiveautomation.com/t/tag-change-execute-script/65751/8 "2022-10-27T16:15:26Z")

</div>

> [@Thiago\_Vilela](#):
>
> def valueChanged(self, previousV

`<cough>` Post your code (using the \</\> code formatting button).`</cough>`

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [October 27, 2022, 5:57pm UTC](https://forum.inductiveautomation.com/t/tag-change-execute-script/65751/9 "2022-10-27T17:57:22Z")

</div>

> [@Transistor](#):
>
> > [@Thiago\_Vilela](#):
> >
> > def valueChanged(self, previousV
> 
> `<cough>` Post your code (using the \</\> code formatting button).`</cough>`

I changed.  
Thanks
