# runScript in tag expression fails

**URL:** <https://forum.inductiveautomation.com/t/runscript-in-tag-expression-fails/28458>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [September 22, 2019, 6:47pm UTC](https://forum.inductiveautomation.com/t/runscript-in-tag-expression-fails/28458 "2019-09-22T18:47:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecollier](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@ecollier](https://forum.inductiveautomation.com/u/ecollier)\
**Post date:** [September 22, 2019, 6:47pm UTC](https://forum.inductiveautomation.com/t/runscript-in-tag-expression-fails/28458/1 "2019-09-22T18:47:57Z")

</div>

I have a tag expression containing runScript which is failing. When I look in tag diagnostics I get the error:

Error executing script for runScript() expression:shared.dars.batch.getInstanceCount(215,2).

However, if I run shared.dars.batch.getInstanceCount(215,2) from the script console, it returns a value.

Any ideas?

---

<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:** [September 22, 2019, 7:11pm UTC](https://forum.inductiveautomation.com/t/runscript-in-tag-expression-fails/28458/2 "2019-09-22T19:11:22Z")

</div>

There are many scripting features that are different in gateway scopes compared to client or designer scope. Especially in gateway global scope (versus gateway project scope). You don’t show the actual getInstanceCount() function, so we can’t help you find the problem. But look up all uses of system.\* functions in the manual to see the differences in usage.

---

<div class="post-metadata">

**Author:** ![ecollier](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@ecollier](https://forum.inductiveautomation.com/u/ecollier)\
**Post date:** [September 22, 2019, 7:20pm UTC](https://forum.inductiveautomation.com/t/runscript-in-tag-expression-fails/28458/3 "2019-09-22T19:20:36Z")

</div>

The only system.\* functions in use are system.tag.browseTags and system.tag.read. This was working on my 7.9.9 machine but does not work on my 7.9.10 machine.

code:

def getInstanceCount(entryId, unitId):

```
instanceCount = 0
# get the tagpath for the startId
recipeFolder = getRecipeFolder(unitId) # does a system.tag.read based upon unitId
tagFilter="*/" + str(entryId) + "_*"
tagList = system.tag.browseTags(parentPath=recipeFolder, tagPath=tagFilter, recursive=False)
for tag in tagList:
	fullPath = tag.fullPath
	tagPath = fullPath + "/eventCount"
	instanceCount = system.tag.read(tagPath).value

return instanceCount
```

---

<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:** [September 22, 2019, 8:34pm UTC](https://forum.inductiveautomation.com/t/runscript-in-tag-expression-fails/28458/4 "2019-09-22T20:34:16Z")

</div>

I’ts usually a good idea to fully qualify your function when you run them in the gateway scope. getRecipeFolder() may not make it into the scope of getInstance, otherwise.

---

<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:** [September 23, 2019, 12:33am UTC](https://forum.inductiveautomation.com/t/runscript-in-tag-expression-fails/28458/5 "2019-09-23T00:33:57Z")

</div>

I suspect the difference is that your tag references, wherever they are, are relying on the project’s default tag provider. In gateway global scope, this must be included in all relevant string arguments. Gateway global scope is outside of any project, so there’s no “default” to fall back on.

---

<div class="post-metadata">

**Author:** ![ecollier](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@ecollier](https://forum.inductiveautomation.com/u/ecollier)\
**Post date:** [September 23, 2019, 1:13pm UTC](https://forum.inductiveautomation.com/t/runscript-in-tag-expression-fails/28458/6 "2019-09-23T13:13:39Z")

</div>

You are correct. The function getRecipeFolder(unitId) apparently worked previously because the tag it was reading was in the default tag provider. When I reinstalled on 7.9.10, I moved those tags to a new tag provider. Thank you!
