# Scripting in Tag Expressions

**URL:** <https://forum.inductiveautomation.com/t/scripting-in-tag-expressions/66652>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [November 17, 2022, 8:43pm UTC](https://forum.inductiveautomation.com/t/scripting-in-tag-expressions/66652 "2022-11-17T20:43:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![steven.rehnborg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.rehnborg/32/4952_2.png) [@steven.rehnborg](https://forum.inductiveautomation.com/u/steven.rehnborg)\
**Post date:** [November 17, 2022, 8:43pm UTC](https://forum.inductiveautomation.com/t/scripting-in-tag-expressions/66652/1 "2022-11-17T20:43:25Z")

</div>

Is it possible to run a user defined script in an expression for a tag? I am trying to convert an OPC tag from an integer value in BCD format into an integer value. I have a script that functions in the script console, but will not run in the expression. My assumption at this point is that it is not permitted in the expression. My expression is:  
runScript("DataConversions.BCDtoDEC",0 ,{[default]Forming/DECnumber.value}).

I always get the following error:

Error\_ExpressionEval("Error executing script for runScript() expression:DataConversions.BCDtoDEC")

Adder: I am using the script as an expression in a numeric text field and it functions correctly. I need indirect tags for this application and using the script in the tag seemed liked the best method.

---

<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:** [November 17, 2022, 8:47pm UTC](https://forum.inductiveautomation.com/t/scripting-in-tag-expressions/66652/2 "2022-11-17T20:47:44Z")

</div>

Is the `DataConversions` script in the global scripting project? If not, you will need to move it there (or otherwise arrange inheritance for it).

---

<div class="post-metadata">

**Author:** ![steven.rehnborg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.rehnborg/32/4952_2.png) [@steven.rehnborg](https://forum.inductiveautomation.com/u/steven.rehnborg)\
**Post date:** [November 17, 2022, 8:51pm UTC](https://forum.inductiveautomation.com/t/scripting-in-tag-expressions/66652/3 "2022-11-17T20:51:55Z")

</div>

I have been looking at the global scripting project information and am uncertain about the functioning of it. I just recently upgraded from 7.9 and my old functions are still working, but this is a new script. My global scripting project is set to global  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/f/2f4c5bd20b5c13c7731a830d021d1c07201ec87e.png)

---

<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:** [November 17, 2022, 9:10pm UTC](https://forum.inductiveautomation.com/t/scripting-in-tag-expressions/66652/4 "2022-11-17T21:10:14Z")

</div>

In v7.9, your script would have to be placed in the `shared` function to be usable by tags. After upgrading, all of that is placed in the `global` project as a convenience, and the global scripting project set accordingly. Place your `DataConversions` script in the global project, not any other.

Or create a project just for tag scripting, set it to be your global scripting project, and do all script functions for tags there.

---

<div class="post-metadata">

**Author:** ![steven.rehnborg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.rehnborg/32/4952_2.png) [@steven.rehnborg](https://forum.inductiveautomation.com/u/steven.rehnborg)\
**Post date:** [November 18, 2022, 12:11pm UTC](https://forum.inductiveautomation.com/t/scripting-in-tag-expressions/66652/5 "2022-11-18T12:11:13Z")

</div>

Does changing the global scripting project affect my v7.9 scripts?

---

<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:** [November 18, 2022, 1:19pm UTC](https://forum.inductiveautomation.com/t/scripting-in-tag-expressions/66652/6 "2022-11-18T13:19:47Z")

</div>

Yes, for tag events and anything else from v7.9 that wasn't part of a project. If you create a new project to be your global scripting project, have it inherit from the current global project. Then the new global scripting project will include the prior `shared.*` scope, and tag events that need that will still work.

---

<div class="post-metadata">

**Author:** ![steven.rehnborg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.rehnborg/32/4952_2.png) [@steven.rehnborg](https://forum.inductiveautomation.com/u/steven.rehnborg)\
**Post date:** [November 18, 2022, 4:33pm UTC](https://forum.inductiveautomation.com/t/scripting-in-tag-expressions/66652/7 "2022-11-18T16:33:29Z")

</div>

I set the global scripting project to a new location and located the scripts there, but my tag expression will still not access the 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:** [November 18, 2022, 6:21pm UTC](https://forum.inductiveautomation.com/t/scripting-in-tag-expressions/66652/8 "2022-11-18T18:21:46Z")

</div>

You might need support to look over your shoulder, then. I'm out of ideas.

---

<div class="post-metadata">

**Author:** ![steven.rehnborg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.rehnborg/32/4952_2.png) [@steven.rehnborg](https://forum.inductiveautomation.com/u/steven.rehnborg)\
**Post date:** [November 30, 2022, 4:23pm UTC](https://forum.inductiveautomation.com/t/scripting-in-tag-expressions/66652/9 "2022-11-30T16:23:01Z")

</div>

Found solution. It was caused by the Gateway Scripting Project setting. I mistakenly thought "Project" was not referencing the project I was working in and set the value incorrectly.
