# How to reset inheritance on UDT instances value change script through scripting

**URL:** <https://forum.inductiveautomation.com/t/how-to-reset-inheritance-on-udt-instances-value-change-script-through-scripting/53095>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [November 15, 2021, 7:43pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-inheritance-on-udt-instances-value-change-script-through-scripting/53095 "2021-11-15T19:43:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathan1](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@nathan1](https://forum.inductiveautomation.com/u/nathan1)\
**Post date:** [November 15, 2021, 7:43pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-inheritance-on-udt-instances-value-change-script-through-scripting/53095/1 "2021-11-15T19:43:47Z")

</div>

We have a few UDT instances that have inadvertently had their value change script overridden (through human error). Is there a way to force the UDT instance properties back to inheriting from the UDT value change script?

I saw this post about reverting UDT inheritance but can’t seem to make it work for the value change script: [Overriding Properties in UDT Instances by system.tag.writeAsync() - #4 by witman](https://forum.inductiveautomation.com/t/overriding-properties-in-udt-instances-by-system-tag-writeasync/32516/4)

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [November 15, 2021, 7:47pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-inheritance-on-udt-instances-value-change-script-through-scripting/53095/2 "2021-11-15T19:47:53Z")

</div>

Yes, just retire the “Overriden” option (keep it gray to reference de UDT)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/3/63fe0c2e2b142c1d21a7f93d30aa47d6cd683d8e.png)

Note that ones you hit “Commit” the old script will be lost.

---

<div class="post-metadata">

**Author:** ![nathan1](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@nathan1](https://forum.inductiveautomation.com/u/nathan1)\
**Post date:** [November 15, 2021, 7:48pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-inheritance-on-udt-instances-value-change-script-through-scripting/53095/3 "2021-11-15T19:48:50Z")

</div>

Thanks for the reply. Yes, it’s easy through the designer but we have a large amount of tags so I need to detect and revert through scripting.

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [November 15, 2021, 8:03pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-inheritance-on-udt-instances-value-change-script-through-scripting/53095/4 "2021-11-15T20:03:02Z")

</div>

oh, that would no be possible as far as I know.  
Maybe you can do:  
1.- Export a tag that you know that has the script the references de UDT, you will see something like this

```auto
#No Overriden
{
  "name": "tag",
  "tagType": "AtomicTag"
}

```

2.- Run a recursive and append all tag path where you find something different than expected. (Add a filter to only check tags witch belong to your UDT name)

```auto
#Overriden
{
  "eventScripts": [
    {
      "eventid": "valueChanged",
      "script": "\tif currentValue.value \u003d\u003d 1:\n\t\tsystem.util.getLogger(\u0027new\u0027).info(\u0027script\u0027)"
    }
  ],
  "name": "tag",
  "tagType": "AtomicTag"
}

```

3.- I would compare if you find the key “eventScripts” and also the “script” value itself. If theses are different so it means it was overriden.  
4.- Ones you have your list of paths, sadly. You’ll need to manually disable the “overriden”

---

<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:** [November 15, 2021, 9:07pm UTC](https://forum.inductiveautomation.com/t/how-to-reset-inheritance-on-udt-instances-value-change-script-through-scripting/53095/5 "2021-11-15T21:07:10Z")

</div>

[`jq`](https://stedolan.github.io/jq/) could probably do it; it’s pretty easy if you don’t care about _any_ event scripts, just delete the entire `eventScripts` node for everything under a UDT instance.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 16, 2021, 3:06am UTC](https://forum.inductiveautomation.com/t/how-to-reset-inheritance-on-udt-instances-value-change-script-through-scripting/53095/6 "2021-11-16T03:06:34Z")

</div>

If you know that it’s the only thing overridden, then using jq you could only apply your deletion if the object contains just the name and tagType members, then you won’t be affecting other tags with actual scripts

---

<div class="post-metadata">

**Author:** ![nathan1](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@nathan1](https://forum.inductiveautomation.com/u/nathan1)\
**Post date:** [November 16, 2021, 3:48am UTC](https://forum.inductiveautomation.com/t/how-to-reset-inheritance-on-udt-instances-value-change-script-through-scripting/53095/7 "2021-11-16T03:48:01Z")

</div>

I ended up using a hackish way to achieve this by resetting the entire tag to the UDT definition then writing back values that I want to preserve. Not ideal but definitely better than manually resetting them. jq looks pretty slick. Will definitely check it out.

```auto
tags = system.tag.browseTags(parentPath="[default]Devices")
preserve = ['io_device_id','io_device_name', 'map', 
            'map_x','map_y', 'voice_alert','notes'] 

for tag in tags:	

    cache = {}

	for p in preserve:
        path = tag.path + '/%s' % p
		val = system.tag.read(path).value 
        cache[p] = val #store preserved tag value

    reset = {'name': tag.name}
    system.tag.configure(tag.path, reset, 'o') #reset the entire tag

    for p in preserve:
        path = tag.path + '/%s' % p
        system.tag.write(path, cache[p]) #write back previous value

```
