Scripting in Tag Expressions

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.

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

1 Like

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

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.

1 Like

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

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.

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.

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

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.

1 Like