Enable valueChanged eventScript using system.tag.getConfiguration

Is there a way to enable an eventScript that exist on a tag via script? I've tried using the system.tag.getConfiguration method but I keep getting an error stating 'Bad_Unsupported - The target path cannot accept children tags'.

Does anyone happen to have an example or have been able to successful accomplish this?

Post your code and format it using the </> button.

path = "[METERS]TEST_ENABLE"

Get current tag configuration

config = system.tag.getConfiguration(path, True)[0]
scriptEnabled = eventScripts[0]['enabled']=True 
system.tag.configure(path, [config], "o")

Please see Wiki - how to post code on this forum.

config = system.tag.getConfiguration(path, True)[0]
scriptEnabled = eventScripts[0]['enabled']=True
system.tag.configure(path, [config], "o")

Your script is referencing an undefined variable. It should be something like:

config = system.tag.getConfiguration(path,True)[0]['eventScripts']
config[0]['enabled'] = True
system.tag.configure(path,[config],'o')

Ahhh good catch. I actually had it written out quite a few ways and forgot to update the variable. It still throws an error, even when I correct the variable name.

[Error_Configuration("java.lang.IllegalArgumentException: Error converting non dictionary object to tag edit.")

You'll have to show your script as written when the error was produced.

path = "[METERS]TEST_ENABLE"


config = system.tag.getConfiguration(path,True)[0]['eventScripts']
config[0]['enabled'] = True
system.tag.configure(path,[config],'o')

There's a slight mismatch between system.tag.getConfiguration and system.tag.configure in that the latter expects the path supplied to be the folder in which to work, where the former will enumerate a folder if given a folder, but returns a single-entry list if given a path to an actual tag.

Change the path supplied to system.tag.configure to exclude the leaf tag name.

2 Likes

Thank you!

Now I am getting a KeyError on 'eventScripts'.

path = "[METERS]ENABLE_SCRIPT/TEST_ENABLE
basePath = "[METERS]ENABLE_SCRIPT"


config = system.tag.getConfiguration(path,True)[0]['eventScripts']
config[0]['enabled'] = True
system.tag.configure(basePath,[config],'o')

Here is the config that is returned.

{u'tags': [{u'path': TEST_ENABLE, u'tagType': AtomicTag, u'name': u'TEST_ENABLE', u'eventScripts': [{u'eventid': u'valueChanged', u'script': u'\tsystem.perspective.print("HI")', u'enabled': False}], u'valueSource': u'memory'}], u'path': [METERS]ENABLE_SCRIPT, u'tagType': Folder, u'name': u'ENABLE_SCRIPT'}

Got a working example, thanks for the help!

tagObject = {
	'eventScripts':[{
		"eventid": "valueChanged",
		"script": "\t test",
		"enabled":True
	}],
	'name':'scriptTagTest'
 
}
 
basePath= '[Cochina]'
system.tag.configure(basePath, [tagObject],'m')