Data type of tag custom property


When using scrip console to create a tag with custom properties, how do you set the datatype of the custom property?

It seems like if I pass a string as value the datatype automatically sets to unicode. And if I pass a number as value the datatype automatically sets to float. But what if I want it to be an integer?

It’s probably not important, I’d just like to know :slight_smile:

provider = '[SCADA]'
tagpath = provider+'test'
tagname = 'tag_prop_test'
tagtype = 'Float4'
enabled = True
ro = False
val = 999
tag = {}
tag.update(name = tagname)
tag.update(valueSource = 'memory')
tag.update(dataType = tagtype)
tag.update(enabled = True)
tag.update(readOnly = ro)
tag.update(value = val)
tag.update(Trend_Data = int(9)) # the custom parameter, typecasting doesn't seem to work?

print "Initial config                                   ", system.tag.configure(tagpath,[tag],'o'), tagpath, tagname

t1 = system.tag.readBlocking(tagpath+'/'+tagname+'.Trend_Data')[0].value
print "Read tag value and datatype                      ", t1, type(t1)

# get config -> change datatype of custom parameter -> write back the changed config.
# --> datatype still float idstead of int?

c1 = system.tag.getConfiguration(tagpath+'/'+tagname, 0)[0]

print "Read tag config value and datatype               ", c1['Trend_Data'], type(c1['Trend_Data'])

c1['Trend_Data'] = int(9)
#c1['Trend_Data'] = None # remove the custom parameter

print "Changed config value and datatype                ", c1['Trend_Data'], type(c1['Trend_Data'])

print "Write back changed config                        ", system.tag.configure(tagpath, c1, 'o')

t1 = system.tag.readBlocking(tagpath+'/'+tagname+'.Trend_Data')[0].value
print "Read updated tag value and datatype              ", t1, type(t1)


1 Like

I am having a similar issue, but I cant seem to create a custom property as anything other than a string. In the below code both DesiredHigh and DesiredLow are created and set as type string…

## read tag configuration from tagPath
tag = system.tag.getConfiguration(value,False)[0]

if 'DesiredHigh' not in tag or 'DesiredLow' not in tag:
	## Find path to parent tag folder
	a = str(tag['path'])
	parentPath = a.rsplit('/',1)[0]
	## add custom properties to tag configuration
	tag['DesiredHigh']= 0.2
	tag['DesiredLow']= '0'
	## write modified tag configuration back to tag
	system.tag.configure(parentPath, tag,"m")

Post early morning brain fade I realised that casting the value being written to the custom property seems to work fine.


tag[‘DesiredHigh’]= int(55)
tag[‘DesiredLow’]= int(66)
1 Like

I still can’t seem to get it working.
I still get float as datatype even if I typecast it’s value.
I updated my test code. Could you try to see if the test code works in your script console?
Did you check the datatype of the custom parameters after you did the
system.tag.configure(parentPath, tag,"m")
to see if it’s still an int?

My test code gives me the following output

Initial config                                    [Good] [SCADA]test tag_prop_test
Read tag value and datatype                       9.0 <type 'float'>
Read tag config value and datatype                9.0 <type 'float'>
Changed config value and datatype                 9 <type 'int'>
Write back changed config                         [Good]
Read updated tag value and datatype               9.0 <type 'float'>

Note that the changed config shows value 9 and type int correctly, but when writing back the changed config to the tag the value and datatype remains 9.0 and float for some reason?


I have a follow up to this. Is there a way to dynamically change the dataTypes of custom properties through script after they are already put in?

What I have tried so far:

If I run a script to add a custom property the only way I could get the dataType to change was based on the value it gets, as the above had mentioned. IF the value is True/False the data type will change to Boolean, etc.

This is fine with initial setup but what if I want to change the datatype of a custom property/properties after the fact?

I have tried the following:

#UDT Definitnon:
topFolder = "[TopFolder]_types_/TopFolder/TopFolder_TAG"

tagObject = [{
			'PI_Tag': {'dataType':'String', 'value': 'test'}

system.tag.configure(topFolder, tagObject, 'm')

The output from this is incorrect. is comes up on the definition as and on the instance as
The JSON gives an error but the value of the custom property comes out like an array:

Value '{ "dataType": "String", "value": "test" }

Error when coping the JSON from the UDT definition:

GatewayException: Value '{
    "dataType": "String",
    "value": "test"
}', of type 'Document', cannot be converted to the type 'Boolean' which is expected by the property 'PI_Tag'.
	caused by PropertyTypeException: Value '{
    "dataType": "String",
    "value": "test"
}', of type 'Document', cannot be converted to the type 'Boolean' which is expected by the property 'PI_Tag'.

Ignition v8.1.36 (b2024010211)
Java: Azul Systems, Inc. 17.0.8

I could not find any documentation on dataTypes of custom properties/how to script them in the Ignition docs.

The only solution I found so far...
Delete the custom property entirely then add it back in the way you need the dataType to be. This is great if we are not on a live site but other than that, this is not my first choice in solving this.