# runScript PathToTag Property

**URL:** <https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [June 10, 2024, 9:13pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656 "2024-06-10T21:13:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [June 10, 2024, 9:13pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/1 "2024-06-10T21:13:42Z")

</div>

I am trying to run a script from an expression tag using `runScript`

The script works, given the correct arguments.

```python
Common.Data.histArrayToDataset('Pumps_Motors/2111-WP/Runtime_Starts/History/1/0/Chart.Path')

```

However, trying to run the script via expression I'm having trouble getting the path into the call.

```python
runScript("Common.Data.histArrayToDataset",5000,{PathToTag},"False")

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/3/7329cc3c32bfcc1be420dd543f33888580b598d9.png)

It doesn't seem to substitute the PathToTag into the expression.  
I've also tried creating a custom "Path" prop that's bound to `{PathToTag}` but then I get a script error.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/b/2ba865770ccd5c49f3ddae1fa7cbaf49d704021c.png)

---

<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:** [June 10, 2024, 9:22pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/2 "2024-06-10T21:22:25Z")

</div>

Try  
`runScript("Common.Data.histArrayToDataset",5000,"{PathToTag}","False")`

Some UDT meta parameters are automatically substituted in _before_ they're handed off to the rest of Ignition, including expression evaluation, for processing.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [June 10, 2024, 9:23pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/3 "2024-06-10T21:23:32Z")

</div>

Same error. Still not substituted into the expression.

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

I should see the actual path in that expression property, correct?

---

<div class="post-metadata">

**Author:** ![Cory.grube](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cory.grube/32/20476_2.png) [@Cory.grube](https://forum.inductiveautomation.com/u/Cory.grube)\
**Post date:** [June 10, 2024, 9:39pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/4 "2024-06-10T21:39:36Z")

</div>

I know that UDT params evaluate to their live value in `opcItemPath`. Tested on my end (8.1.41) and it seems that the `expression` prop **does not** evaluate in the same way (at least not in the tag browser - I'll defer to Paul wrt the behavior under the hood).

> [@amarks](#):
>
> `Common.Data.histArrayToDataset('Pumps_Motors/2111-WP/Runtime_Starts/History/1/0/Chart.Path')`  
> ...  
> `runScript("Common.Data.histArrayToDataset",5000,{PathToTag},"False")`

You have an extra parameter in the `runScript`. You also might need it to be `False` instead of `"False"`, if it's needed at all.

---

<div class="post-metadata">

**Author:** ![Cory.grube](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cory.grube/32/20476_2.png) [@Cory.grube](https://forum.inductiveautomation.com/u/Cory.grube)\
**Post date:** [June 10, 2024, 9:49pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/5 "2024-06-10T21:49:57Z")

</div>

A few more things I noticed. Your script console test passes a string to `*.path`, which I assume you evaluate with `system.tag.read*`? This returns a path that includes the `[tagProvider]`. `{PathToTag}` does not include the `[tagProvider]`.

Further, if you're using doing a `system.tag.read*` on {PathToTag}, you'll get that tag's value, not its path.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [June 10, 2024, 9:51pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/6 "2024-06-10T21:51:23Z")

</div>

~~Provider or not, doesn't matter.~~ My script creates relative tag paths and reads them.

The path is being passed to the script so that it can create those relative paths.

```python
def histArrayToDataset(path, rev = False):
	'''
		Create a dataset of historical records (no dates).
		Historical record paths are created based on relative paths.
		Call from the "Chart" dataset tag that is contained in the same folder as historical records 0-9.
		
		Args:
			path	(string)	:	path to the resulting dataset chart tag
			rev (bool) :	reverse order. Default 9 -> 0.
			
		Returns:
			dataset	(dataset)	:	dataset with historical records
	'''
	#get parent tag folder path
	parentFolder = path.rsplit('/',1)[0]
	#append tags to read
	if not rev:
		tagsToRead = [parentFolder+'/'+str(num) for num in range(9,-1,-1)]
	else:
		tagsToRead = [parentFolder+'/'+str(num) for num in range(0,10)]
	
	#read the value for historical data points
	histData = [tag.value for tag in system.tag.readBlocking(tagsToRead)]
	#print histData
	
	#dataset headers and empty data list initialization
	headers = ['t_stamp','value']
	data = []

```

---

<div class="post-metadata">

**Author:** ![Cory.grube](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cory.grube/32/20476_2.png) [@Cory.grube](https://forum.inductiveautomation.com/u/Cory.grube)\
**Post date:** [June 10, 2024, 10:02pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/7 "2024-06-10T22:02:36Z")

</div>

I see - thanks for providing the script. Loosely tested in the script console on my end. It makes sense and seems to behave how I'd expect.

I'd try setting up some loggers with `system.util.getLogger` to verify the `{PathToTag}` is getting sent correctly. ~~You might also have luck passing `{[.].path}` instead of `{PathToTag}`~~ **(Edit: Made dumb mistakes. See [later post](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/18))**

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [June 10, 2024, 10:12pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/8 "2024-06-10T22:12:02Z")

</div>

that's basically what I was trying to do with the custom `path` property, bound to `{PathToTag}` I can even see the entire path in the property in the tag browser.

> [@amarks](#):
>
> ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/b/2ba865770ccd5c49f3ddae1fa7cbaf49d704021c.png)

---

<div class="post-metadata">

**Author:** ![Cory.grube](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cory.grube/32/20476_2.png) [@Cory.grube](https://forum.inductiveautomation.com/u/Cory.grube)\
**Post date:** [June 10, 2024, 10:23pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/9 "2024-06-10T22:23:05Z")

</div>

Sure, I understand that's what you're going for. But you'll want to set up a logger, print to the wrapper logs, return the path early, etc to 100% verify that `runScript` is passing the correct parameter.

Also, just want to echo my earlier note about `False` vs `"False"`. Python truthiness will interpret the latter as `True`, as it's a string with `len()` \> 0. It's not affecting the current issue, but it might cause you headaches in the future.

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [June 10, 2024, 11:41pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/10 "2024-06-10T23:41:42Z")

</div>

> [@amarks](#):
>
> `runScript("Common.Data.histArrayToDataset",5000,{PathToTag},"False")`

why your boolean param is set "False" on runscript ? it is a String,  
path of tag must be sommething like :`[provider]Test1/tes2/temp_1`

I think @Cory.grube is true. you must create a log to see if the params that you are sending is correct

this :[doc](https://www.docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/advanced/runScript) will help you.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [June 10, 2024, 11:41pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/11 "2024-06-10T23:41:51Z")

</div>

I did some testing, and using `{PathToTag}` without quotes works fine.

As @Cory.grube mentioned, you'll want to take your `"False"` out of quotes.

I suspect the reason it may not be working may be two-fold. You're not returning anything from the script you provided. It's also possible you don't have your Gateway Scripting Project configured to the project your script is located inside.

Edit: One other thing is that in the tag browser, the expression doesn't populate with the path to the tag and stays as `{PathToTag}` so if you were looking at that as your troubleshooting, that won't work, and you'll have to follow the advice of others and do some logging to see if your values are getting passed properly or not.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [June 11, 2024, 1:22pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/12 "2024-06-11T13:22:04Z")

</div>

There is a return statement, I just omitted the creation and return of the resultant dataset (for no real reason) - but you can see the successful return of a dataset from my first post

> [@amarks](#):
>
> ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/3/7329cc3c32bfcc1be420dd543f33888580b598d9.png)

@sebastien_ng the `rev` parameter's default value is `False`.

I am getting a dataset returned now with `runScript("Common.Data.histArrayToDataset",5000,{PathToTag},False)` but it has 0 rows.

Path passed with runscript, from my logger:  
`path : Pumps_Motors/2112-WP/Runtime_Starts/History/1/0/Chart`  
So, it doesn't pass the provider for some reason, but if I create a custom "path" property on the tag and bind it to `{PathToTag}` it does include the provider...?  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/9/699f871b391ecfc029733db7bbe663d48427d838.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/e/ceeb4d9482e3a8a1f698f9318a7c4739bf19b077.png)

but now I get an error when trying to pass the custom property

```python
runScript("Common.Data.histArrayToDataset",5000,{[.]Chart.Path},False)

```

In the logger now:

```python
path : {path} 

```

So, weird again. My prop was named "path". If I have a prop named "SPath" it doesn't include the provider.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/8/08f2509873b80cafc016676fc979a289128edeff.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/7/b7530b39445838708921e1d7e22a791b94f9ff9b.png)

If I run in the console without the provider I get the 0R dataset, so that must be my issue. So, why can't I get that "Path" passed in?

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [June 11, 2024, 1:59pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/13 "2024-06-11T13:59:33Z")

</div>

are you executing this runscript on a popup view ?

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [June 11, 2024, 2:00pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/14 "2024-06-11T14:00:10Z")

</div>

Try this : copy you tag path on you custom `PathToTag`  
something like :  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/7/77b1ef7645d1a62a6b6108c37f319870a5cae930.png)

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [June 11, 2024, 2:10pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/15 "2024-06-11T14:10:17Z")

</div>

I can get it to work in-view no problem

---

<div class="post-metadata">

**Author:** ![Cory.grube](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cory.grube/32/20476_2.png) [@Cory.grube](https://forum.inductiveautomation.com/u/Cory.grube)\
**Post date:** [June 12, 2024, 5:48pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/16 "2024-06-12T17:48:48Z")

</div>

> [@amarks](#):
>
> So, weird again. My prop was named "path". If I have a prop named "SPath" it doesn't include the provider.

`path` is a property that natively exists on tags/folders/etc, but isn't usually visible in the tag browser. I'm kind of surprised it let you create a custom property called `path`. That may be leading to the inconsistent `{PathToTag}` behavior.

I suspect your custom property is being silently ignored, but haven't tested. ~~You could try removing your custom `path` and again passing `{[.]this.path}` or `{[.].path}`.~~ **(Edit: Made dumb mistakes. See [later post](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/18))**

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [June 12, 2024, 6:55pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/17 "2024-06-12T18:55:23Z")

</div>

> [@Cory.grube](#):
>
> `path` is a property that natively exists on tags/folders/etc, but isn't usually visible in the tag browser. I'm kind of surprised it let you create a custom property called `path`. That may be leading to the inconsistent `{PathToTag}` behavior.

I thought that might be the case as well.  
I have tried `{[.].path} with no luck`

I can read `[Water]Pumps_Motors/2111-WP/Runtime_Starts/History/1/0/Chart.Path` with `system.tag.readBlocking()` so I should have access to it from the expression within the UDT, right?

no dice for `{[.]this.path}` either

---

<div class="post-metadata">

**Author:** ![Cory.grube](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cory.grube/32/20476_2.png) [@Cory.grube](https://forum.inductiveautomation.com/u/Cory.grube)\
**Post date:** [June 12, 2024, 8:32pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/18 "2024-06-12T20:32:29Z")

</div>

> [@amarks](#):
>
> I can read `[Water]Pumps_Motors/2111-WP/Runtime_Starts/History/1/0/Chart.Path` with `system.tag.readBlocking()` so I should have access to it from the expression within the UDT, right?

Yup, you should be able to access it from anywhere.

> [@amarks](#):
>
> I have tried `{[.].path} with no luck`  
> ...  
> no dice for `{[.]this.path}` either

Big apologies, I made some very dumb mistakes on both of these suggestions. I'll update my previous posts.

First, I had the context for the relative path `{[.].path}` wrong. This would actually return the path of the parent folder, not the path of your expression tag.

Second, I had the syntax wrong for the [`this` keyword](https://docs.inductiveautomation.com/docs/8.1/platform/tags/tag-paths#using-the-this-keyword). Correct syntax is `{this.path}`.

Below are example outputs for `{[.].path}` and `{this.path}`:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/d/9d20eb3ef067101dd8f6287f49ca7d594d7bd439.png)

Does `{this.path}` solve your original issue?

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [June 12, 2024, 10:41pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/19 "2024-06-12T22:41:00Z")

</div>

Thanks for the update. No, `{this.path}` does not work either.

Just for S&G I overrode the expression on the instance with a string literal with the path with the same call and _ **it should** _ work, if the string can get substituted in there.

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

If I use `"'"+{this.path}+"'"` and print to the diagnostics I get `'[Water]Pumps_Motors/2111-WP/Runtime_Starts/History/1/0/Chart'` in the logs

edit:

```python
runScript("Common.Data.histArrayToDataset",5000,toStr({this.path}),False)

```

works. Just have to convert the string to a string 🙃

---

<div class="post-metadata">

**Author:** ![Cory.grube](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cory.grube/32/20476_2.png) [@Cory.grube](https://forum.inductiveautomation.com/u/Cory.grube)\
**Post date:** [June 12, 2024, 11:17pm UTC](https://forum.inductiveautomation.com/t/runscript-pathtotag-property/91656/20 "2024-06-12T23:17:41Z")

</div>

Nice, glad you got it working!

The typecast bit is interesting - I'm guessing the path ends up being passed as one of the Java tag path types (BasicTagPath?), rather than a string. Doesn't change much - I'd just typecast it as you did.
