# Unable to add scripting to tags

**URL:** <https://forum.inductiveautomation.com/t/unable-to-add-scripting-to-tags/86552>\
**Category:** General Discussion\
**Created:** [February 28, 2024, 9:47pm UTC](https://forum.inductiveautomation.com/t/unable-to-add-scripting-to-tags/86552 "2024-02-28T21:47:25Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raghavendra\_Pra\_Gatt](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Raghavendra\_Pra\_Gatt](https://forum.inductiveautomation.com/u/Raghavendra_Pra_Gatt)\
**Post date:** [February 28, 2024, 9:47pm UTC](https://forum.inductiveautomation.com/t/unable-to-add-scripting-to-tags/86552/1 "2024-02-28T21:47:25Z")

</div>

Hello,  
I am trying to code where I would like to create tags which has alarm info and custom script(on value changed). I was able to create tags with alarm without any issues but when I want to create tags with alarm and scripting info I'm getting issues. Can anyone please help me?

 ![Ignition Issue](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/e/2e134e3d6eddc04bd2853bfbd8b54c7ed4a27f5d.png)

---

<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:** [February 28, 2024, 9:49pm UTC](https://forum.inductiveautomation.com/t/unable-to-add-scripting-to-tags/86552/2 "2024-02-28T21:49:05Z")

</div>

1. Post your code _as code_, via the preformatted text \</\> button above the post.
2. Post any actual error messages you're seeing, because "issues" is not nearly enough information to provide meaningful help.

---

<div class="post-metadata">

**Author:** ![Raghavendra\_Pra\_Gatt](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Raghavendra\_Pra\_Gatt](https://forum.inductiveautomation.com/u/Raghavendra_Pra_Gatt)\
**Post date:** [February 28, 2024, 9:54pm UTC](https://forum.inductiveautomation.com/t/unable-to-add-scripting-to-tags/86552/3 "2024-02-28T21:54:41Z")

</div>

```auto
		customscript = """
			currentVal =currentValue.value
			if currentValue.value != previousValue.value:
				eventType = 'Lane 100% Full'
				description = 'EE4401-1 100% FULL'
				if currentVal == 1:
					parameters = {'area':tagPath.split('/')[-2],'site':tagPath.split('/')[1],'eventType':eventType,'startTime':system.date.now(),'device':tagPath.split('/')[-1],'description':description}
					system.db.runNamedQuery('AddNewDowntimeEvent',parameters)
				elif currentVal == 0:
					parameters = {'area':tagPath.split('/')[-2],'site':tagPath.split('/')[1],'eventType':eventType,'endTime':system.date.now(),'device':tagPath.split('/')[-1],'description':description}
					system.db.runNamedQuery('UpdateLatestDowntimeWithEndtime',parameters)
		"""
		alarm = [
		            {
		                "name":alarmName,
		                "displayPath": alarmPath,               
		                "mode":"AboveValue",               
		                "setpointA":0,
		                "inclusiveA":False
		            }
		        ]  
		tag = {
		            "name": tagName,           
		            "opcItemPath" : opcItemPath,
		            "opcServer": opcServer,
		            "valueSource": valueSource,
		            "sampleMode" : sampleMode,
		            "tagGroup" : tagGroup,
		            "alarms": alarm,
		           "eventScripts": [{"eventGroupName": "valueChanged", "script": customscript}]
		        }
		system.tag.configure(finalTagPath, tag, collisionPolicy)

```

---

<div class="post-metadata">

**Author:** ![Raghavendra\_Pra\_Gatt](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Raghavendra\_Pra\_Gatt](https://forum.inductiveautomation.com/u/Raghavendra_Pra_Gatt)\
**Post date:** [February 28, 2024, 9:56pm UTC](https://forum.inductiveautomation.com/t/unable-to-add-scripting-to-tags/86552/4 "2024-02-28T21:56:42Z")

</div>

I'm not getting errors while executing this code, but no tag is getting created.  
If comment out eventScripts ,I was able to create tag with alarm info

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [February 28, 2024, 9:59pm UTC](https://forum.inductiveautomation.com/t/unable-to-add-scripting-to-tags/86552/5 "2024-02-28T21:59:48Z")

</div>

You've put the script in triple quotes turning the entire thing into one string.

Triple quotes are only needed for e.g. multiline SQL statements.

---

<div class="post-metadata">

**Author:** ![Raghavendra\_Pra\_Gatt](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Raghavendra\_Pra\_Gatt](https://forum.inductiveautomation.com/u/Raghavendra_Pra_Gatt)\
**Post date:** [February 28, 2024, 10:30pm UTC](https://forum.inductiveautomation.com/t/unable-to-add-scripting-to-tags/86552/6 "2024-02-28T22:30:58Z")

</div>

When I use ' ' or " " for customscript shown in above, I'm getting errors while executing script

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 28, 2024, 11:01pm UTC](https://forum.inductiveautomation.com/t/unable-to-add-scripting-to-tags/86552/7 "2024-02-28T23:01:19Z")

</div>

> [@Raghavendra\_Pra\_Gatt](#):
>
> I'm getting errors

What errors?

---

<div class="post-metadata">

**Author:** ![Raghavendra\_Pra\_Gatt](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Raghavendra\_Pra\_Gatt](https://forum.inductiveautomation.com/u/Raghavendra_Pra_Gatt)\
**Post date:** [February 29, 2024, 1:00am UTC](https://forum.inductiveautomation.com/t/unable-to-add-scripting-to-tags/86552/8 "2024-02-29T01:00:43Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/e/6e322f7388e1b38d0256636f1b09cf04ff878cb7.png)  
If I use " " for custom script

```auto
		customscript = "
			currentVal =currentValue.value
			if currentValue.value != previousValue.value:
				eventType = 'Lane 100% Full'
				description = 'EE4401-1 100% FULL'
				if currentVal == 1:
					parameters = {'area':tagPath.split('/')[-2],'site':tagPath.split('/')[1],'eventType':eventType,'startTime':system.date.now(),'device':tagPath.split('/')[-1],'description':description}
					system.db.runNamedQuery('AddNewDowntimeEvent',parameters)
				elif currentVal == 0:
					parameters = {'area':tagPath.split('/')[-2],'site':tagPath.split('/')[1],'eventType':eventType,'endTime':system.date.now(),'device':tagPath.split('/')[-1],'description':description}
					system.db.runNamedQuery('UpdateLatestDowntimeWithEndtime',parameters)
		"
		
		alarm = [
		            {
		                "name":alarmName,
		                "displayPath": alarmPath,               
		                "mode":"AboveValue",               
		                "setpointA":0,
		                "inclusiveA":False
		            }
		        ]  
		tag = {
		            "name": tagName,           
		            "opcItemPath" : opcItemPath,
		            "opcServer": opcServer,
		            "valueSource": valueSource,
		            "sampleMode" : sampleMode,
		            "tagGroup" : tagGroup,
		            "alarms": alarm,
		           "eventScripts": [{"eventGroupName": "valueChanged", "script": customscript}]
		        }

		system.tag.configure(finalTagPath, tag, collisionPolicy)

```

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [February 29, 2024, 1:38pm UTC](https://forum.inductiveautomation.com/t/unable-to-add-scripting-to-tags/86552/9 "2024-02-29T13:38:26Z")

</div>

Already told you, you are turning your script into a string.

It should look something like this:

```auto
            currentVal =currentValue.value
			if currentValue.value != previousValue.value:
				eventType = 'Lane 100% Full'
				description = 'EE4401-1 100% FULL'
				if currentVal == 1:
					parameters = {'area':tagPath.split('/')[-2],'site':tagPath.split('/')[1],'eventType':eventType,'startTime':system.date.now(),'device':tagPath.split('/')[-1],'description':description}
					system.db.runNamedQuery('AddNewDowntimeEvent',parameters)
				elif currentVal == 0:
					parameters = {'area':tagPath.split('/')[-2],'site':tagPath.split('/')[1],'eventType':eventType,'endTime':system.date.now(),'device':tagPath.split('/')[-1],'description':description}
					system.db.runNamedQuery('UpdateLatestDowntimeWithEndtime',parameters)
		
		
		alarm = [
		            {
		                "name":alarmName,
		                "displayPath": alarmPath,               
		                "mode":"AboveValue",               
		                "setpointA":0,
		                "inclusiveA":False
		            }
		        ]  
		tag = {
		            "name": tagName,           
		            "opcItemPath" : opcItemPath,
		            "opcServer": opcServer,
		            "valueSource": valueSource,
		            "sampleMode" : sampleMode,
		            "tagGroup" : tagGroup,
		            "alarms": alarm,
		           "eventScripts": [{"eventGroupName": "valueChanged", "script": customscript}]
		        }

		system.tag.configure(finalTagPath, tag, collisionPolicy)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 29, 2024, 2:14pm UTC](https://forum.inductiveautomation.com/t/unable-to-add-scripting-to-tags/86552/10 "2024-02-29T14:14:40Z")

</div>

I understand. You are trying to configure the tag with an event script. But the event scripts on a tag are a _single element for all scripts_ on the tag.

You should carefully examine the results from `system.tag.getConfiguration()` for an existing tag that has the script(s) you want. You will need to produce a matching structure for `system.tag.configure()`.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 29, 2024, 2:19pm UTC](https://forum.inductiveautomation.com/t/unable-to-add-scripting-to-tags/86552/11 "2024-02-29T14:19:47Z")

</div>

customscript is the script being added to the tag. It will need to be triple quoted.

Looking at one of my test tags with a script of:

```auto
x = 1
y = 2

```

yields:

```auto
{
  "valueSource": "memory",
  "eventScripts": [
    {
      "eventid": "valueChanged",
      "script": "\tx \u003d 1\n\ty \u003d 2"
    }
  ],
  "dataType": "Boolean",
  "name": "TestBool",
  "value": false,
  "tagType": "AtomicTag"
}

```

So, "eventid" instead of "eventGroupName" may be enough to fix it.

---

<div class="post-metadata">

**Author:** ![Raghavendra\_Pra\_Gatt](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Raghavendra\_Pra\_Gatt](https://forum.inductiveautomation.com/u/Raghavendra_Pra_Gatt)\
**Post date:** [February 29, 2024, 2:48pm UTC](https://forum.inductiveautomation.com/t/unable-to-add-scripting-to-tags/86552/12 "2024-02-29T14:48:49Z")

</div>

Thanks everyone for your responses. Thanks Jordon, changing to "eventid" instead of "eventGroupName" has fixed my issue having triple quotes to my custom script """ """
