Hi,
I have a script to rename a UDT instance and it seems like a datetime member loses its override on system.tag.configure
To reproduce:
Create an instance of a UDT, containing some memory tag members. This is an example UDT definition.
{
"name": "TestRename",
"typeId": "",
"tagType": "UdtType",
"tags": [
{
"valueSource": "memory",
"dataType": "DateTime",
"name": "DateTime",
"formatString": "yyyy-MM-dd h:mm:ss aa",
"tagType": "AtomicTag"
},
{
"valueSource": "memory",
"dataType": "Document",
"name": "Document",
"tagType": "AtomicTag"
},
{
"valueSource": "memory",
"dataType": "Boolean",
"name": "Boolean",
"tagType": "AtomicTag"
},
{
"valueSource": "memory",
"name": "Integer",
"tagType": "AtomicTag"
},
{
"valueSource": "memory",
"dataType": "String",
"name": "String",
"tagType": "AtomicTag"
},
{
"valueSource": "memory",
"dataType": "Float4",
"name": "Float",
"tagType": "AtomicTag"
}
]
}
I use the following script to rename the instance:
def rename(tagPath, newName):
#Get the current tag config
try:
configs = system.tag.getConfiguration(tagPath, True) #Must be recursive to get child config
name = configs[0]['name']
baseTagPath = tagPath.replace('/'+name, '')
configs[0]['name'] = newName
#Check if the destination does not already exist to avoid wiping another tag
if not system.tag.exists(baseTagPath + '/' + newName):
#create the new tag
system.tag.configure(baseTagPath, configs, "o")
#Check if create was successful and delete original tag
if system.tag.exists(baseTagPath + '/' + newName):
delete(tagPath)
except Exception as e:
pass
def delete(tagPath):
#Delete, do not care about success
system.tag.deleteTags([tagPath])
rename ('[default]Test/name2', 'name1')
Any value that was set in the datetime member is lost. The others preserve their values.
If you print the value of the config, the value is there.
This behaviour is not present when renaming a tag through the tag browser.
I see there used to be a system.tag.rename
function, but it appears deprecated. If there is a better way to programmatically rename a tag, please do let me know.
Regards,
Deon
(Using 8.1.7)