# runScript() Pass a tag as parameter possible?

**URL:** <https://forum.inductiveautomation.com/t/runscript-pass-a-tag-as-parameter-possible/24597>\
**Category:** Ignition\
**Created:** [May 2, 2019, 3:09pm UTC](https://forum.inductiveautomation.com/t/runscript-pass-a-tag-as-parameter-possible/24597 "2019-05-02T15:09:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leeroy](https://avatars.discourse-cdn.com/v4/letter/l/eb9ed0/32.png) [@leeroy](https://forum.inductiveautomation.com/u/leeroy)\
**Post date:** [May 2, 2019, 3:09pm UTC](https://forum.inductiveautomation.com/t/runscript-pass-a-tag-as-parameter-possible/24597/1 "2019-05-02T15:09:59Z")

</div>

Hi guys ,

I’m trying to pass Tags as parameter to a script but it’s not working . Is it possible?

**Here is my expression:**

`runScript("shared.backgroundcolor.backgroundcolor",{[Master_par_Tags]Batching/A220/AGT SPT/AGT1_PLC/SPT_1_},{[Master_par_Tags]Batching/A220/AGT SPT/AGT1_PLC/SPT_2_})`

**Here is the error that i get.**  
caused by ClassCastException: Error trying to coerce ‘{[Master\_par\_Tags]Batching/A220/AGT SPT/AGT1\_PLC/SPT\_1\_}’ to a number.

I’m guessing that the script is waiting to receive a number as a parameter but i would like to send tags as a parameter.

**Here is my script (it’s is only a test)**  
**Please note that if I replace the parameter in the script TagsDB and TagsPLC and running the script without using runScript it is working . Thanks**

```auto
def backgroundcolor(TagsDB,tagsPLC):
	
	endTime = system.date.now()
	startTime = system.date.now()
	dataset=system.tag.queryTagHistory(paths=['TagsDB'], startDate=startTime, endDate=endTime, returnSize=1, aggregationMode="Maximum", returnFormat='Wide')
	print dataset.getValueAt(0,1)

	tagsr=(["tagsPLC"])
	valuer=system.tag.readAll(tagsr)

	print valuer[0].value
	if valuer[0].value != dataset.getValueAt(0,1):
		print 'different'

```

---

<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:** [May 2, 2019, 3:30pm UTC](https://forum.inductiveautomation.com/t/runscript-pass-a-tag-as-parameter-possible/24597/2 "2019-05-02T15:30:38Z")

</div>

Your first problem is that you’re skipping a required argument for the `runScript` function - if you’re passing _any_ arguments, you must also pass a rate. If it’s an expression tag, leave the rate 0 so that the script evaluates at the scan class execution rate:  
`runScript("shared.backgroundcolor.backgroundcolor", 0, {[Master_par_Tags]Batching/A220/AGT SPT/AGT1_PLC/SPT_1_},{[Master_par_Tags]Batching/A220/AGT SPT/AGT1_PLC/SPT_2_})`

Your second problem is that what you’re trying to do doesn’t really make sense. You’re passing in the _values_ of tags to a function that then tries to use those as tagpaths. In _expressions_, the curly brace around a tagpath (`{[Master_par_Tags]Batching/A220/AGT SPT/AGT1_PLC/SPT_2_}`) means evaluate and return _the value of this tag_. But, your defined function is (attempting to) act like it’s getting tag _paths_, which it’s not. If you do actually want to pass tagpaths to your script, then drop the curly braces:  
`runScript("shared.backgroundcolor.backgroundcolor", 0, "[Master_par_Tags]Batching/A220/AGT SPT/AGT1_PLC/SPT_1_", "[Master_par_Tags]Batching/A220/AGT SPT/AGT1_PLC/SPT_2_")`

Finally, your script is not interpeting the tagpaths correctly; you’re not using the parameters passed into the script at all:  
`def backgroundcolor(TagsDB, tagsPLC):`  
means that when your script executes, it will have access to two local variables: `TagsDB` and `tagsPLC`. With the modified `runScript` expression posted above, those will now be literal strings. However, in your code you’re doing things like:  
`dataset=system.tag.queryTagHistory(paths=['TagsDB']`  
`'TagsDB'` is _another_ literal string at this point - it has no relation whatsoever to the `TagsDB` variable that already exists. Drop the quotes around the parameters, because they’re completely defeating the purpose of what you’re trying to do. Also, if you’re running this from anything “gateway” scoped (ie, an expression tag) the `print` statements are only going to show up in the `wrapper.log` file - nowhere else.

---

<div class="post-metadata">

**Author:** ![leeroy](https://avatars.discourse-cdn.com/v4/letter/l/eb9ed0/32.png) [@leeroy](https://forum.inductiveautomation.com/u/leeroy)\
**Post date:** [May 2, 2019, 4:18pm UTC](https://forum.inductiveautomation.com/t/runscript-pass-a-tag-as-parameter-possible/24597/3 "2019-05-02T16:18:07Z")

</div>

Thanks for your help and quick answer great service provided by all of you guys!  
I new to scripting and didn’t know all this !

It’s all working now !!
