TagEvent script in system.tag.addTag()


I was looking for a way to insert a script or bind a function to a TagEvent whitin the system.tagaddTag().
Is it possible?


Using addTag()? No. Using configure()? Yes.

newTag = {}
newTag["name"] = "Some New Tag"
newTag["expressionType"] = "Expression"
newTag["expression"] = 'dateExtract(now(),"second")'
newTag["eventScripts"] = [{"eventid":"valueChanged","script":"\tprint \"Hello World\""}]

system.tag.configure(path="",tags = system.util.jsonEncode(newTag))

Thank you Kyle_Chase! I’ll give a try…

It works great! But I didn’t find any kind of documentation about system.tag.configure()…like it doesn’t exist

Here is another example to build the same tag as I did in my above example. It is using the TagConfigurationBuilder and TagConfigProps to help build the tag. As an alternative, you could also use the output of system.tag.browseConfiguration().toJSON() to get the dictionary properties.

from com.inductiveautomation.ignition.common.tags.config import TagConfigurationBuilder,TagConfigProps
from com.inductiveautomation.ignition.common.sqltags.model.types import DataType,TagType
from com.inductiveautomation.ignition.common.sqltags.model.scripts import BasicTagEventScripts

tagEvents = BasicTagEventScripts()
tagEvents.set("valueChanged","\tprint \"Hello World\"")

t = (TagConfigurationBuilder()
	.name("Some New Tag2")

system.tag.configure(path = "",tags = t)

Like I said, 2 ways to skin this cat.

More than 2 ways to skin the cat, another (possibly more clunky) way is to use system.tag.loadFromFile

You guys are great! Thank you, I solved my issue…