Dynamic tag binding of an array though scripting

Hello, I read in other threads that this is not possible, but I wanted to get some more information on other possible ways.
I have a FlexRepeater with the “instances” array bound to a script that generates a list of arrays with this structure:
0:
UDT:
data: value
MHE: value1

The script basically gets the tag provider and selects some tags in a for loop to generate the instances of a template by returning a list with this structure

udtInstances.append({
'MHE': tagName,
'UDT': {
'data': value,
}
})

I need to bind the UDT array in my instances to different tags that the script selects. Can I pass through this script the binding information? Or can you point me in the right direction?

Any help would be appreciated.
Thank you

Wrong approach, configure your embedded view to accept a tag path string. Pass the UDT tag path to the embedded view. On your embedded view, use the base UDT tag path to drive indirect bindings for each of the necessary UDT members. Each member should have its own private custom property at the view level. Bind display/control elements to these custom properties as necessary.

While this is for a popup, the exact same method can be used for views in a repeater:

While this link is for vision, the same logic can be applied to perspective:

1 Like
  1. Use tag function system.tag.browse using the folder path, you can use the filter parameter to get a specific UDT type.
folder_path = "[path]to_folder"
output = []
results = system.tag.browse(folder_path) 
for result in results:
  output.append(result['fullPath'])
  1. With that result you can create an array of tag paths, and add the tag address.
tags_to_read = []
for path in output:
  tags_to_read.append(str(path) + '/Val')
  1. With that array of tagpaths, use a system read function to get all the values,
qualifiedValues = system.tag.readBlocking(tags_to_read)
  1. You'll get an array of values, with that array you can create a flex repeater with the format you need.

Be careful with the system.tag.readBlocking function, this function creates a thread in the gateway, don't use it with constant generated data, this is perfect to get the configuration, if you need to have a constant reading it's better to use system.tag.readAsync.

This is incorrect and inefficient, if you need anything other than a value snapshot, you should be utilizing (indirect) tag bindings. If the values are being displayed via embedded views, the bindings should be configured in the embedded view and generated from the tag path(s) passed to the embedded view as parameters.

Edited to clarify

Fair point, Ryan. Indirect tag bindings are definitely more efficient for standard UI displays. However, since we don't know exactly how many tags need to be read, configuring individual bindings would be inefficient. As he mentioned needing these for a Flex Repeater, another alternative would be to pass the tagPath to the repeater and let the child view handle the indirect tagging. That said, I find that scripting often provides better maintainability when dealing with dynamic arrays that reads more that just one value of the UDT. But you're right, for a single value snapshot, bindings are the way to go.

It appears I was unclear, I was advising to create the indirect tag bindings on the embedded view as you mentioned. I've edited my comment to prevent confusion.

1 Like

This is what @pturmel ‘s Integration Toolkit module solves with the tags expression function which accepts a list of tagpaths to create bindings to

2 Likes