# UDT to power table

**URL:** <https://forum.inductiveautomation.com/t/udt-to-power-table/33028>\
**Category:** Ignition\
**Created:** [March 11, 2020, 9:29pm UTC](https://forum.inductiveautomation.com/t/udt-to-power-table/33028 "2020-03-11T21:29:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![john.eichler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/john.eichler/32/24632_2.png) [@john.eichler](https://forum.inductiveautomation.com/u/john.eichler)\
**Post date:** [March 11, 2020, 9:29pm UTC](https://forum.inductiveautomation.com/t/udt-to-power-table/33028/1 "2020-03-11T21:29:34Z")

</div>

Hi All

I have around 20 UDT tags, all the same UDT. I would like to display several variables from each UDT in a table row.

The desired result would be as below (but with more rows). I have accomplished this by configuring the power table by “cell update” and manually addressing each cell. This is laborous and difficult to maintain.

Is there a way to populate each row by indirect addressing or some other method?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/5cc984d47b27caf3dab851dd321013789a1d39ba.png)

Thanks

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 12, 2020, 1:38am UTC](https://forum.inductiveautomation.com/t/udt-to-power-table/33028/2 "2020-03-12T01:38:25Z")

</div>

I would read all the tags at once, then use a script to massage your values into a dataset for the table.

Without knowing your UDT structure or folder layout, that’s all I can recommend.

---

<div class="post-metadata">

**Author:** ![john.eichler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/john.eichler/32/24632_2.png) [@john.eichler](https://forum.inductiveautomation.com/u/john.eichler)\
**Post date:** [March 12, 2020, 1:47am UTC](https://forum.inductiveautomation.com/t/udt-to-power-table/33028/3 "2020-03-12T01:47:15Z")

</div>

Thanks.

I did consder this option but I was concerned about the peformance impact of a script running every few seconds. The user interface will require “live” data.

The UDTs are very simple and contain only 2 integers and 1 or 2 strings as shown in the table.

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

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 12, 2020, 1:51am UTC](https://forum.inductiveautomation.com/t/udt-to-power-table/33028/4 "2020-03-12T01:51:12Z")

</div>

Looks like it’ll be pretty straightforward. Except I’m not quite up to writing an example on my phone. 😄

I’m off to bed, but I’ll try to pop something up in the morning.

---

<div class="post-metadata">

**Author:** ![john.eichler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/john.eichler/32/24632_2.png) [@john.eichler](https://forum.inductiveautomation.com/u/john.eichler)\
**Post date:** [March 12, 2020, 10:37am UTC](https://forum.inductiveautomation.com/t/udt-to-power-table/33028/5 "2020-03-12T10:37:13Z")

</div>

I look forward to your reply.

The following works. I have triggered it from a button click on the screen. The script populates a custom property (dataset) which is sent to the table. It’s pretty rough. I’m sure there is a nicer way to do the data selection and the table needs to be updated in real time, not on a button press.

```auto
#Create an empty dataset
data = []

#Create the dataset for the headers
headers = ["Description", "Battery remaining (weeks)", "Signal strength (dB)"]

#Return only DeltaOhmED tags in the specified directory.
results = system.tag.browse(path = '[HamJet_Tags]Fabrication/Devices', filter = {'typeId':'DeltaOhmED'})

for result in results.getResults():
    
    # If the item has children, call the function to repeat the process but starting at the child.
    if result['hasChildren'] == True:
		result2=system.tag.browse(result['fullPath'], {})

		for result in result2.getResults():
        		
        		#Store the description
          		if result['name']=='Description':
          			desc = result['value'].value
          		
          		#Store the battery		
          		if result['name']=='BatteryRemaining':
          			batt = result['value'].value
          		
          		#Store the signal	
          		if result['name']=='SignalStrength':
          			signal = result['value'].value 
	
		# Add a row of data to the dataset
		data.append([desc,batt,signal])
		
# Add the data to the headers.
event.source.parent.data = system.dataset.toDataSet(headers,data)

```

[https://docs.inductiveautomation.com/display/DOC80/system.tag.browse](https://docs.inductiveautomation.com/display/DOC80/system.tag.browse)

[https://docs.inductiveautomation.com/display/DOC79/Datasets](https://docs.inductiveautomation.com/display/DOC79/Datasets)

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [March 12, 2020, 12:13pm UTC](https://forum.inductiveautomation.com/t/udt-to-power-table/33028/6 "2020-03-12T12:13:44Z")

</div>

You could pass the tag path to the page or table and then use indirect bindings to display the values from the individual tags in the UDT.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 12, 2020, 6:03pm UTC](https://forum.inductiveautomation.com/t/udt-to-power-table/33028/7 "2020-03-12T18:03:35Z")

</div>

Sorry for the late reply…

I’m finding that the tag browse filter doesn’t always filter when there’s stuff I want to filter. 😕 I was not able to filter on the _typeId_, but was able to filter on tagType.

My method reads the tags within the UDT. the _keys_ list are the relative paths within the UDT.

It will create the tag, then group the values according the number of keys you have. So, if you need to add a column, you only need to adjust the _key_ and _headers_ lists.

One browse operation, one tag read operation.

Note this script, as written, will only hit tags on the root level of the UDT.

```python

tagPath = '[HamJet_Tags]Fabrication/Devices'
udtID = 'DeltaOhmED'

keys = ["Description", "BatteryRemaining", "SignalStrength"]
headers = ["Description", "Battery remaining (weeks)", "Signal strength (dB)"]

# Browse the tags. Filters on tagType to look only for UDT instances,
# which seems to work.
browse = system.tag.browse(path = tagPath, filter = {'tagType':'UdtInstance'})

# Create tag names from browse results and keys. Filtering on typeID here seems to be more robust. 
tagsIn = [str(r['fullPath']) + '/' + key for r in browse.getResults() for key in keys if r['typeId'] == udtID]

# Get tag values
values = [t.value for t in system.tag.readBlocking(tagsIn)]

# Group the values by the number of keys
data = [values[i:i+len(keys)] for i in range(0, len(values)-(len(keys)-1), len(keys))]

# Add the data to the headers.
event.source.parent.data = system.dataset.toDataSet(headers,data)

```

---

<div class="post-metadata">

**Author:** ![john.eichler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/john.eichler/32/24632_2.png) [@john.eichler](https://forum.inductiveautomation.com/u/john.eichler)\
**Post date:** [March 12, 2020, 8:33pm UTC](https://forum.inductiveautomation.com/t/udt-to-power-table/33028/8 "2020-03-12T20:33:29Z")

</div>

Thanks very much for the reply! I’ll try to get my head around this later today.

---

<div class="post-metadata">

**Author:** ![john.eichler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/john.eichler/32/24632_2.png) [@john.eichler](https://forum.inductiveautomation.com/u/john.eichler)\
**Post date:** [March 13, 2020, 1:28am UTC](https://forum.inductiveautomation.com/t/udt-to-power-table/33028/9 "2020-03-13T01:28:18Z")

</div>

Hi again.

Although this works, I’d like to further refine the functionality.

Using Jordan’s code from above I now have a dataset of tag paths.

1. How can I use these tag paths to populate a power table so I don’t need to keep running the script to refresh my data?
2. How do I trigger the script to run when a template is loaded? I’ve looked at several forum posts such as [Template load event?](http://forum.inductiveautomation.com/t/template-load-event/16237/4) but when I add this to PropertyChange, ignition throws an error upon saving.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 13, 2020, 8:30am UTC](https://forum.inductiveautomation.com/t/udt-to-power-table/33028/10 "2020-03-13T08:30:21Z")

</div>

> [@john.eichler](#):
>
> How can I use these tag paths to populate a power table so I don’t need to keep running the script to refresh my data?

I recommend using a gateway timer event script and write the results to a dataset tag. Then point the table to the dataset tag. The results will always be up to date.

---

<div class="post-metadata">

**Author:** ![hwbrill](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hwbrill/32/14377_2.png) [@hwbrill](https://forum.inductiveautomation.com/u/hwbrill)\
**Post date:** [May 30, 2020, 3:45am UTC](https://forum.inductiveautomation.com/t/udt-to-power-table/33028/11 "2020-05-30T03:45:19Z")

</div>

I kind of want to accomplish the same thing but use a single column dataset tag for a drop down list of folders, representing each opc ua server device on the gateway using system.tag.browse. Also, create a single and multiple column dataset tags referencing multiple sub folders which each sub folder having multiple duties types list the name in a dataset as reference to a template repeater. I was looking at gateway script and/or derived tag?
