System.tag.configure with UDTs in Folder

Hi,

I’m trying to create a script that will take UDT definitions from one provider and distribute it to other providers on the same gateway. EAM can send it to the source provider on each gateway and this script can send it to the rest of the tag providers.

The issue I’m experiencing is that the configuration on the target somehow inserts a _types _ subfolder. See code and result below:

def syncUDTs(sourceProvider, targetProviders = None):

	configs = system.tag.getConfiguration('['+sourceProvider+']_types_/Test Folder', True)
	for target in targetProviders:
		system.tag.configure('['+target+']_types_', configs, "o")
	
	return

syncUDTs('Development', targetProviders = ['udtSync'])

image

The config doesn’t seem to contains _types _ subfolder under the Test Folder, hence I don’t know how to get rid of it. See configs below (the print mangled the quotations):

[
    {'tags': [
            {'path': Test UDT 2, 'tagType': UdtType, 'name': 'Test UDT 2', 'typeId': None
            },
            {'path': Test UDT 1, 'tagType': UdtType, 'name': 'Test UDT 1', 'typeId': None
            }
        ], 'path': [Development]_types_/Test Folder, 'tagType': Folder, 'name': 'Test Folder'
    }
]

Is this a bug or can I somehow get the UDTs into the target while preserving the original structure?

Thanks,
Deon

2 Likes

Has this issue been resolved? I’m having the same problem.

I just tried this in 8.1.17 and ran into the same issue. It seems a “types” parent folder is added to the whole configuration as well as above the type definitions in any subfolders (original tag configuration read did not include the highlighted folders below):
image
Has anyone found a workaround for this?

I did solve this, but it involve some string manipulation to filter out the types

2 Likes

In case anyone else runs into this, I wanted to pass along my solution.

I couldn't find any string manipulation that made sense, but did find that removing the 'path' keys from all dictionaries returned from system.tag.getConfiguration eliminated the _types_ folders that were erroneously being added.

This does not appear to work as expected if you are utilizing UDT Inheritance with overridden values. If you are then tags with an overridden value will be duplicated instead.
Edit: A hacky solution is to run the system.tag.configure function twice with 'o' for the collision policy. I'm pretty sure the root issue has something to do with the parent UDT getting created after the child UDT.

Example code below

global_udt_folder_path = '[global]_types_/global_UDTs'


def remove_path_keys(udt_configs):
	if isinstance(udt_configs, list):
		return [remove_path_keys(item) for item in udt_configs]
	elif isinstance(udt_configs, dict):
		return {
			key: remove_path_keys(value)
			for key, value in udt_configs.items()
			if key != "path"
		}
	else:
		return udt_configs


def global_udts():
	udt_configs = system.tag.getConfiguration(global_udt_folder_path, True)
	udt_configs = remove_path_keys(udt_configs)
	system.tag.configure('[default]_types_', udt_configs, 'o')