# Undo tag writes and restore old value

**URL:** <https://forum.inductiveautomation.com/t/undo-tag-writes-and-restore-old-value/38526>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [September 9, 2020, 3:56pm UTC](https://forum.inductiveautomation.com/t/undo-tag-writes-and-restore-old-value/38526 "2020-09-09T15:56:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![d.iannozzi](https://avatars.discourse-cdn.com/v4/letter/d/ecd19e/32.png) [@d.iannozzi](https://forum.inductiveautomation.com/u/d.iannozzi)\
**Post date:** [September 9, 2020, 3:56pm UTC](https://forum.inductiveautomation.com/t/undo-tag-writes-and-restore-old-value/38526/1 "2020-09-09T15:56:14Z")

</div>

Hi everyone,  
i need to check a value tag written in a numeric text box on a window (vision).  
I want to save the value of the tag and check what the user inputs ; I need to be able to undo the tag changes and write back the old value and refresh the textbox…  
what is the best way to accomplish this ??

thanks in advance,  
Dominic

---

<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:** [September 9, 2020, 5:13pm UTC](https://forum.inductiveautomation.com/t/undo-tag-writes-and-restore-old-value/38526/2 "2020-09-09T17:13:51Z")

</div>

Im assuming that you cant use the useBounds of the numeric text box.

So it depends on how often you need to do it. If it is just a few times then you can take care of this in the propertyChange script of the components. Much more then that and you’ll need a more centralized method.

I would create a shared/project script utility to enforce your limits, something like the following:

```auto
def commitTagWrite(self, tagPath, newValue, oldValue, lowLimit, highLimit):
     if newValue:
          if newValue != oldValue and newValue >= lowLimit and newValue <= highLimit:
               system.tag.write(tagPath,newValue)
               return True
     return False

```

On the component, do not bind directly to the tag. Instead, in the scripting do something like this:

```auto
if event.propertyName == 'value':
     if not project.scriptName.commitTagWrite('your tag path',event.newValue, event.oldValue, 0,100):
          event.value = oldValue

```

It may be worth adding a custom property to the component/template to hold the tagPath so it isn’t hard coded, but again that is dependent on how many times you need to do this.

This would write the new value if it was between 0 - 100, the oldValue if it was outside those limits, and do nothing if the newValue is None.

You can also wrap all of this in a Try/Except block and use a Logger for various things. Probably not a bad idea especially if you have several of these to do.

Of course there may be a better way of accomplishing the task that I am not aware of.

---

<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:** [September 9, 2020, 5:15pm UTC](https://forum.inductiveautomation.com/t/undo-tag-writes-and-restore-old-value/38526/3 "2020-09-09T17:15:41Z")

</div>

Instead of binding the tag directly to the entry field’s editable property, bind it to a custom property–I like to name such properties `Raw`. Then uni-directionally bind the editable property to the raw property. I also like to make another property named `Dirty` with an expression comparing `Raw` to editable property. Then you can style the component based on whether it matches the current tag value. When you do this use separate “Save” and “Cancel” buttons. The former would write to the tags with the edited value, and the latter would copy the `Raw` property value over the editable property.

---

<div class="post-metadata">

**Author:** ![d.iannozzi](https://avatars.discourse-cdn.com/v4/letter/d/ecd19e/32.png) [@d.iannozzi](https://forum.inductiveautomation.com/u/d.iannozzi)\
**Post date:** [September 10, 2020, 4:46pm UTC](https://forum.inductiveautomation.com/t/undo-tag-writes-and-restore-old-value/38526/4 "2020-09-10T16:46:57Z")

</div>

Hi guys  
thankyou for your time…will proceed with your suggestions.

best regards  
Dominic
