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

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

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

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

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.

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

#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)

#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”

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.

1 Like

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

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.

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
1 Like