# How can you display a script dataset in a Perspective Table?

**URL:** <https://forum.inductiveautomation.com/t/how-can-you-display-a-script-dataset-in-a-perspective-table/81492>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [November 4, 2023, 12:34am UTC](https://forum.inductiveautomation.com/t/how-can-you-display-a-script-dataset-in-a-perspective-table/81492 "2023-11-04T00:34:36Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![r123](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@r123](https://forum.inductiveautomation.com/u/r123)\
**Post date:** [November 4, 2023, 12:34am UTC](https://forum.inductiveautomation.com/t/how-can-you-display-a-script-dataset-in-a-perspective-table/81492/1 "2023-11-04T00:34:36Z")

</div>

I have a script working in the script console that creates a dataset. The Perspective table doesn't seem to have a script binding.

I tried creating a Memory dataset and binding the table to it but I get an error when trying to write to the script dataset to the Memory dataset tag.

```auto
[Error_TypeConversion("class com.inductiveautomation.ignition.common.tags.paths.BasicTagPath: Invalid DataType for Dataset.")]

```

I found some posts saying this may have worked in the past but there are now checks to make sure the dataset matches the default format the Memory dataset expects?

```auto
TagPath = "[default]"
tags = system.tag.browse(TagPath, {'tagType': 'Folder', 'recursive': True})
SystemSectorList = []
for tag in tags:
    full_path = tag.get('fullPath', '')
    findLocale = str(system.tag.readBlocking(str(full_path) + ".locale"))
    if "Good" in findLocale:
	    import re
	    
	    # Use a regular expression to extract the first value
	    match = re.search(r'\[\[([^,]+),', findLocale)
	    
	    if match:
	        locale_Value = match.group(1)
	        SystemSectorList.append([full_path, locale_Value])
	        print(locale_Value)
	    else:
	        print("No match found")
print SystemSectorList
SystemSectorHeaders = ['Path ID', 'locale ID']
SystemSector_Dataset = system.dataset.toDataSet(SystemSectorHeaders, SystemSectorList)
print SystemSector_Dataset
system.tag.writeBlocking(["[default]MemoryTags/Tag_locales/locales_dataset"], SystemSector_Dataset)

```

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [November 4, 2023, 12:42am UTC](https://forum.inductiveautomation.com/t/how-can-you-display-a-script-dataset-in-a-perspective-table/81492/2 "2023-11-04T00:42:50Z")

</div>

Bind the dataset code to the "data " property in the perspective table, I have definitely made this work just fine, normally I use it for modifying data coming out of an SQL query using a script transform. So long as the binding returns a dataset, it should display it in the table.

---

<div class="post-metadata">

**Author:** ![r123](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@r123](https://forum.inductiveautomation.com/u/r123)\
**Post date:** [November 4, 2023, 12:50am UTC](https://forum.inductiveautomation.com/t/how-can-you-display-a-script-dataset-in-a-perspective-table/81492/3 "2023-11-04T00:50:53Z")

</div>

One of these? Use the expression to call a script and return a dataset or did you add a Change Script?  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/0/00213a366a7f58e5dad8d7e5018f6c646cb638d3.png)

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [November 4, 2023, 12:54am UTC](https://forum.inductiveautomation.com/t/how-can-you-display-a-script-dataset-in-a-perspective-table/81492/4 "2023-11-04T00:54:58Z")

</div>

Bit of a hack, but you can use the Expression, and enter `now(2000)` and the binding will update at 2000ms rate, then just use the script transform under that, and return the dataset. Otherwise you can bind to any item that you want to trigger the dataset script with, and use that with a script transform.

---

<div class="post-metadata">

**Author:** ![r123](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@r123](https://forum.inductiveautomation.com/u/r123)\
**Post date:** [November 4, 2023, 12:58am UTC](https://forum.inductiveautomation.com/t/how-can-you-display-a-script-dataset-in-a-perspective-table/81492/5 "2023-11-04T00:58:38Z")

</div>

Ok, thanks. I'm using one other script Transform somewhere else. I'll give that a shot.

The Memory Dataset Tag really had me going, like this should be easy and work. It's right in the name. 🙂

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [November 4, 2023, 1:01am UTC](https://forum.inductiveautomation.com/t/how-can-you-display-a-script-dataset-in-a-perspective-table/81492/6 "2023-11-04T01:01:54Z")

</div>

> [@r123](#):
>
> `system.tag.writeBlocking(["[default]MemoryTags/Tag_locales/locales_dataset"], SystemSector_Dataset)`

Also, just noticed that you are passing a list of one tag path, and a dataset, I believe that you should be sending a list and a list.

`system.tag.writeBlocking(["[default]MemoryTags/Tag_locales/locales_dataset"], [SystemSector_Dataset])`

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [November 4, 2023, 1:06am UTC](https://forum.inductiveautomation.com/t/how-can-you-display-a-script-dataset-in-a-perspective-table/81492/7 "2023-11-04T01:06:24Z")

</div>

Bit of a warning, you are calling `system.tag.readBlocking` on a single tag path inside of a for loop. This is going to give you poor performance. It is much better to do a single call to `system.tag.readBlocking` after putting together a list of tag paths.

Something like this should work much better:

```auto
tagPaths = [tag.get('fullPath', '') for tag in tags]
tagLocales = [
	str(qv.value) for qv in system.tag.readBlocking([
		"{}.locale".format(tagPath) for tagPath in tagPaths
	])
]

for idx, tagLocale in enumerate(tagLocales):
	if "Good" in tagLocale:
		match = re.search(r'\[\[([^,]+),', tagLocale)
		if match:
			locale_Value = match.group(1)
			full_path = tagPaths[idx]
			SystemSectorList.append([full_path, locale_Value])

```

You should also pull `import re` to outside of the for loop, you only need to import once, before anything else in the script.

Edit: Realized you needed tag paths on their own, put them into a separate list to be retrieved via index

---

<div class="post-metadata">

**Author:** ![r123](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@r123](https://forum.inductiveautomation.com/u/r123)\
**Post date:** [November 4, 2023, 1:25am UTC](https://forum.inductiveautomation.com/t/how-can-you-display-a-script-dataset-in-a-perspective-table/81492/8 "2023-11-04T01:25:36Z")

</div>

> [@ryan.white](#):
>
> You should also pull `import re` to outside of the for loop, you only need to import once, before anything else in the script.

Thanks, I missed that. I had meant to move it up. This is just my cobbled test script.

> [@ryan.white](#):
>
> calling `system.tag.readBlocking` on a single tag path inside of a for loop

I had thought about that but there are very few folders. It's filtering for folders first then just checking only them. There are like 15 now and the script will not run that often. But every little bit helps. I’ll see if I can add this in.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 4, 2023, 7:33am UTC](https://forum.inductiveautomation.com/t/how-can-you-display-a-script-dataset-in-a-perspective-table/81492/9 "2023-11-04T07:33:17Z")

</div>

> [@r123](#):
>
> ```auto
> findLocale = str(system.tag.readBlocking(str(full_path) + ".locale"))
> if "Good" in findLocale:
> 
> ```

This is a bit ugly, better to use:

```auto
findLocale = system.tag.readBlocking("{}.locale".format(full_path))[0]
if findLocale.quality.good:

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 4, 2023, 10:29am UTC](https://forum.inductiveautomation.com/t/how-can-you-display-a-script-dataset-in-a-perspective-table/81492/10 "2023-11-04T10:29:45Z")

</div>

You could also put the script in the library and call it with `runScript`.

---

<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 4, 2023, 1:22pm UTC](https://forum.inductiveautomation.com/t/how-can-you-display-a-script-dataset-in-a-perspective-table/81492/11 "2023-11-04T13:22:02Z")

</div>

Datasets, themselves, allow just about anything as a column type. But that freedom creates huge problems for Ignition's infrastructure when arbitrary datatypes are stored in tags. So the tag machinery of Ignition checks the columns types of any incoming dataset against a whitelist, and rejects any dataset that doesn't conform.

You have a couple options:

- convert the troublesome columns to some other datatype (stringification is common, if you don't need the functionality of the object's true type), or

- store the dataset in memory, typically in a top-level script library variable, and have your uses look for it there. (You might find my `globalVarMap()` functions in my [Integration Toolkit](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934) module helpful.)

---

<div class="post-metadata">

**Author:** ![r123](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@r123](https://forum.inductiveautomation.com/u/r123)\
**Post date:** [November 4, 2023, 6:04pm UTC](https://forum.inductiveautomation.com/t/how-can-you-display-a-script-dataset-in-a-perspective-table/81492/12 "2023-11-04T18:04:43Z")

</div>

Thanks, I'm glad I slept on it. My next question was going to be how to perform stringification or define the column types and wasn't the list already strings? Just using the string function on the `full_path` variable lets the write of the dataset to the memory dataset tag complete successfully.

---

<div class="post-metadata">

**Author:** ![r123](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@r123](https://forum.inductiveautomation.com/u/r123)\
**Post date:** [November 7, 2023, 12:52am UTC](https://forum.inductiveautomation.com/t/how-can-you-display-a-script-dataset-in-a-perspective-table/81492/13 "2023-11-07T00:52:48Z")

</div>

I'm now trying to make a change based on data in the Table. The cell event script works but I have to hard code the path of the tag I wish to change. I found an example of reading a cells value but I can't get it to work.

`val=self.props.selection.data[0]['Path ID']`

When I type it in the auto complete doesn't show a "`selection`" after "`self.props.`"

It gives me an error: `line 7, in runAction KeyError: Path ID`

There are just the two columns and when I edit the cell in the second column "`locale ID`" I take the value just entered "`event.value`" in the onEditCellCommit script. I just need a way to get the value from the same row in the first column "`Path ID`".

* * *

Looks like some things break if you have a space in the header/column name. After that `self.props.selection.data[0].PathID` still was not found until `enableRowSelection` was set.

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