# runScript command in UDT PLC Tag to get its tag name

**URL:** <https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 25, 2023, 11:28am UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851 "2023-07-25T11:28:38Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nirav\_Sopariwala](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@Nirav\_Sopariwala](https://forum.inductiveautomation.com/u/Nirav_Sopariwala)\
**Post date:** [July 25, 2023, 11:28am UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851/1 "2023-07-25T11:28:38Z")

</div>

Hi,  
I am running simple script to get tag name but it ending up with an error:  
"Error\_ExpressionEval("Error executing script for runScript() expression:default.ReadIniFile.myFunc()")

Tag is connected to the PLC using OPC connection.

script:

def myFunc(text="Hello World!", moreText="Good bye"):  
str(text)  
return text

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/f/bfb44a5d59fb26eb819bd613c2a001fd09e68c1f.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/9/d922e3d13f8156f48b6c887da024c9e8778c99a4.png)

Could someone please help on this?

Thank you

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 25, 2023, 12:39pm UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851/2 "2023-07-25T12:39:52Z")

</div>

Is your function defined in the project set as the Gateway Scripting Project?

If not it must be as tags operate outside of any project.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 25, 2023, 1:18pm UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851/3 "2023-07-25T13:18:20Z")

</div>

What is the line  
`str(text)`  
supposed to do? There is no assignment operator.

Tip: format your code when posting on the forum.  
 ![Formatted code](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/1/e11cdbb3b8348c74916b62652bdd100dd77082cf.png)

Your expression is  
`runScript("default.ReadIniFile.myFunc()")`  
but the path in your screengrab suggests that it should be  
`runScript("generate.ReadIniFile.myFunc()")`.

---

<div class="post-metadata">

**Author:** ![Nirav\_Sopariwala](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@Nirav\_Sopariwala](https://forum.inductiveautomation.com/u/Nirav_Sopariwala)\
**Post date:** [July 25, 2023, 1:32pm UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851/4 "2023-07-25T13:32:10Z")

</div>

Hi Irose

Thank you for your response.  
How do I know function is defined as the Gateway Scripting Project?  
Sorry, I am new to Igntion.

Thank You

---

<div class="post-metadata">

**Author:** ![Nirav\_Sopariwala](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@Nirav\_Sopariwala](https://forum.inductiveautomation.com/u/Nirav_Sopariwala)\
**Post date:** [July 25, 2023, 1:34pm UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851/5 "2023-07-25T13:34:22Z")

</div>

Hi Transistor,

I tried with "generate", it still came back with same error

Thank you

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 25, 2023, 1:37pm UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851/6 "2023-07-25T13:37:57Z")

</div>

No worries.

On the Gateway Page at Config \> Gateway Settings, in the first section there is a place to set the Name of the Gateway Scripting Project.

If you are not editing the project with that name when you add your script to the Script Library, then it isn't in the Gateway Scripting Project.

[https://docs.inductiveautomation.com/display/DOC81/Project+Library#ProjectLibrary-GatewayScriptingProject](https://docs.inductiveautomation.com/display/DOC81/Project+Library#ProjectLibrary-GatewayScriptingProject)

---

<div class="post-metadata">

**Author:** ![Nirav\_Sopariwala](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@Nirav\_Sopariwala](https://forum.inductiveautomation.com/u/Nirav_Sopariwala)\
**Post date:** [July 25, 2023, 1:44pm UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851/7 "2023-07-25T13:44:10Z")

</div>

Hi Irose,

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/8/984bdee8432521974d7d59c9379abf4f3eb6b0d3.png)  
It is empty which means it is not Gateway Scripting Project?

If it is the case then, I cannot use script in the UDT tag?

Thank you again

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 25, 2023, 4:34pm UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851/8 "2023-07-25T16:34:55Z")

</div>

That is correct, if it is blank then there is no Gateway Scripting Project configured.

Scripts that run outside of a project scope (tag scripts, etc...) are not projects and therefore need to be told where to look for the script.

I believe that you can set the Gateway Scripting Project to the name of your project and it should work. If you are only ever going to have the one project this is probably fine, but if you intend to have more than one project, this should probably be a stand alone project.

Often this project is used as the root project and set to inheritable, then all other project inherit from it. That way things inside of the project will also have access to the script.

---

<div class="post-metadata">

**Author:** ![Nirav\_Sopariwala](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@Nirav\_Sopariwala](https://forum.inductiveautomation.com/u/Nirav_Sopariwala)\
**Post date:** [July 26, 2023, 2:16pm UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851/9 "2023-07-26T14:16:40Z")

</div>

Hi Irose,

I did that

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/4/043e8443291e2e29018666300e5b0642bfdb7e8d.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/2/d263a47e0de855fb624c0aa0f42bc23639f52f11.png)  
But it did not work.

Is runScript command line need change?

Thank you

---

<div class="post-metadata">

**Author:** ![Nirav\_Sopariwala](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@Nirav\_Sopariwala](https://forum.inductiveautomation.com/u/Nirav_Sopariwala)\
**Post date:** [July 26, 2023, 2:38pm UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851/10 "2023-07-26T14:38:12Z")

</div>

Hi Irose,

I tried to give it a same name.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/1/e171dc8a88e8dbb81a3eacf226e5610b0108dd4d.png)

but it did not work either.

Thank you

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 26, 2023, 2:57pm UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851/11 "2023-07-26T14:57:06Z")

</div>

It needs to be the project name, not the Gateway Name.

If you look on the Projects Tab in the gateway you can find the name that needs to be entered.

---

<div class="post-metadata">

**Author:** ![Nirav\_Sopariwala](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@Nirav\_Sopariwala](https://forum.inductiveautomation.com/u/Nirav_Sopariwala)\
**Post date:** [July 26, 2023, 3:05pm UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851/12 "2023-07-26T15:05:08Z")

</div>

Hi Irose

sorry!!

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/a/aac25f3a8becc01d4ac091538b9daf6dcc3cff31.png)  
I tried following but it did not work.

Thank you for your support

---

<div class="post-metadata">

**Author:** ![Nirav\_Sopariwala](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@Nirav\_Sopariwala](https://forum.inductiveautomation.com/u/Nirav_Sopariwala)\
**Post date:** [July 26, 2023, 3:17pm UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851/13 "2023-07-26T15:17:05Z")

</div>

I have also put the same name for Gateway scripting project

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/a/ea731383a7060789932da60fe3d66cd987555d68.png)

Do I need to restart designer after changing the name ?

Thank You

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 26, 2023, 3:24pm UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851/14 "2023-07-26T15:24:46Z")

</div>

Okay, let me try to step through this a little bit.

1. Set your Gateway Scripting Project to the name of your project. From your screen shot this looks to be `MD02_WAYVIEW`
2. In your `runScript` expression you need to use the proper path to your function. From your screen shots this looks like it should be: `ReadIniFile.myFunc`
3. `runScript` requires a poll rate be included.

Make those changes and then try this in the expression:

```auto
runScript('ReadIniFile.myFunc',0)

```

---

<div class="post-metadata">

**Author:** ![Nirav\_Sopariwala](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@Nirav\_Sopariwala](https://forum.inductiveautomation.com/u/Nirav_Sopariwala)\
**Post date:** [July 26, 2023, 3:26pm UTC](https://forum.inductiveautomation.com/t/runscript-command-in-udt-plc-tag-to-get-its-tag-name/76851/15 "2023-07-26T15:26:55Z")

</div>

Hi Irose,

It did work.

Thank You very much for your help.
