# Create tag with valueChange event logic in it through scripting

**URL:** <https://forum.inductiveautomation.com/t/create-tag-with-valuechange-event-logic-in-it-through-scripting/42386>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [January 19, 2021, 6:46am UTC](https://forum.inductiveautomation.com/t/create-tag-with-valuechange-event-logic-in-it-through-scripting/42386 "2021-01-19T06:46:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neo](https://avatars.discourse-cdn.com/v4/letter/n/9fc348/32.png) [@Neo](https://forum.inductiveautomation.com/u/Neo)\
**Post date:** [January 19, 2021, 6:46am UTC](https://forum.inductiveautomation.com/t/create-tag-with-valuechange-event-logic-in-it-through-scripting/42386/1 "2021-01-19T06:46:14Z")

</div>

I would like to create a memory tag which has some code in `valueChanged` event through scripting. I know we can use `system.tag.addTag` function to create a tag automatically. But I was not able to figure out if we can use same function to add code in tag events. Creating UDT instance could be one possibility but I want to check this possibility.

- Does anyone tried this before or has any idea, please share.
- Also can we create UDT definition through function?

I am using Ignition v7.9.16.  
Thanks in advance.

---

<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:** [January 19, 2021, 4:51pm UTC](https://forum.inductiveautomation.com/t/create-tag-with-valuechange-event-logic-in-it-through-scripting/42386/2 "2021-01-19T16:51:13Z")

</div>

This is possible, though poorly documented.

You will need to do something like this:

```auto
from com.inductiveautomation.ignition.common.sqltags.model import TagProp
from com.inductiveautomation.ignition.common.sqltags.model.scripts import BasicTagEventScripts

newProp = BasicTagEventScripts()
#newProp.set(eventID,code,enabled)
newProp.set('valueChanged',"	x=1 \n	if x==1:\n print 'This Worked'",True)
system.tag.addTag(parentPath='',name='TestTagMemory',tagType='Memory',dataType='Int2',attributes={TagProp.EventScripts:newProp})

```

---

<div class="post-metadata">

**Author:** ![Neo](https://avatars.discourse-cdn.com/v4/letter/n/9fc348/32.png) [@Neo](https://forum.inductiveautomation.com/u/Neo)\
**Post date:** [January 20, 2021, 9:13am UTC](https://forum.inductiveautomation.com/t/create-tag-with-valuechange-event-logic-in-it-through-scripting/42386/3 "2021-01-20T09:13:24Z")

</div>

Thanks a lot @lrose. This is very helpful.

---

<div class="post-metadata">

**Author:** ![Neo](https://avatars.discourse-cdn.com/v4/letter/n/9fc348/32.png) [@Neo](https://forum.inductiveautomation.com/u/Neo)\
**Post date:** [January 21, 2021, 6:54am UTC](https://forum.inductiveautomation.com/t/create-tag-with-valuechange-event-logic-in-it-through-scripting/42386/4 "2021-01-21T06:54:52Z")

</div>

@lrose Can we also create UDT through scripting?

---

<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:** [January 21, 2021, 4:23pm UTC](https://forum.inductiveautomation.com/t/create-tag-with-valuechange-event-logic-in-it-through-scripting/42386/5 "2021-01-21T16:23:03Z")

</div>

I believe that you can use addTag to create a UDT instance tag, but I don’t believe you can use it to build a UDT definition. I haven’t tried to create a UDT from scripting.

---

<div class="post-metadata">

**Author:** ![Neo](https://avatars.discourse-cdn.com/v4/letter/n/9fc348/32.png) [@Neo](https://forum.inductiveautomation.com/u/Neo)\
**Post date:** [January 22, 2021, 6:00am UTC](https://forum.inductiveautomation.com/t/create-tag-with-valuechange-event-logic-in-it-through-scripting/42386/6 "2021-01-22T06:00:07Z")

</div>

Ok. Thanks for you reply.
