Dataset 'string' value throws Error_TypeConversion in Text Field

I am trying to display a string from a dataset in a text field in Ignition 8.0.12 Vision.

I am getting the string by referencing a specific column and row in the dataset:

{Root Container.tags}[7][0]

I am using the same method to get integers and booleans from the same dataset and those are working correctly in on screen objects such as numerical displays and dropdown lists but for whatever reason the strings from the dataset are causing the onscreen objects to display “Error_TypeConversion”.

I did check the type using python:

ds = system.dataset.toPyDataSet(event.source.parent.tags)
system.gui.messageBox(str(type(ds[0][7])))

2022-01-21 14_53_23-UnityVM - VMware Workstation

From this it tells me that the contents for the dataset ‘cell’ is actually unicode and not a string. I suspect this has something to do with the issue but I am not sure quite how to handle it using Ignition’s expression language.

I am looking for a method to convert the unicode to a string with Expression so that it can be displayed on screen in a text field.

You’re not really providing enough info in the right areas.
Can you show the full details of whatever error you’re getting?
How is the tags property on the root container populated? Where are you writing this expression to extract a particular value?

unicode is a Python 2 type that’s a subclass of basestring, which is how Jython represents all string types. Anywhere a Java String is expected, a Jython str or unicode instance can be supplied, so that’s probably not the source of your problem.

Unless there is another place I can find a more descriptive error message all I am seeing on screen is this:

Where the binding on the 'text' property of the text field is where the expression to extract the value is located.

The tags property is a dataset that is populated using the following script that called the OPC server API and gets back a list of tags in JSON format (in this case just a single tag in the list).

# Import required libraries
import json


# Define finctions
def getKeys(dict):
	return dict.keys()

def getValues(dict):
	return dict.values()

def prefixStrip(string, symbol):
	index = string.find(symbol)
	index += 1
	return(string[index:])


# Define Static Variables
user = "Administrator"
passwd = ""
url = "http://127.0.0.1:57418/config/v1/project/channels/SHY1_INV1101/devices/ADAM4572/tags"


# Main
try:
	response = system.net.httpGet(url=url, username=user, password=passwd)
except IOError as e:
	print(e)
	exit()

# Convert the HTTP response to JSON
json_response = json.loads(response)
			
# Use the keys from the retrived data for the dataset header (potential to run into problem with duplicate column names)
keys = getKeys(json_response[0])

# Strip the prefix from the key Names
for i in range(0, len(keys)):
	keys[i] = prefixStrip(keys[i], ".")

headers = keys
row = []
pydataset = []

# Get values from 1st row of response
for value in getValues(json_response[0]):
	row.append(value)
pydataset.append(row)

dataset = system.dataset.toDataSet(headers, pydataset)
event.source.parent.tags = dataset

The response to my http get request looks like this before the json.loads() call if it helps at all:

[
	{
		"PROJECT_ID": 1869366352,
		"common.ALLTYPES_NAME": "IRRADIANCE",
		"common.ALLTYPES_DESCRIPTION": "IRRADIANCE",
		"servermain.TAG_ADDRESS": "30001",
		"servermain.TAG_DATA_TYPE": 5,
		"servermain.TAG_READ_WRITE_ACCESS": 0,
		"servermain.TAG_SCAN_RATE_MILLISECONDS": 1000,
		"servermain.TAG_AUTOGENERATED": false,
		"servermain.TAG_SCALING_TYPE": 1,
		"servermain.TAG_SCALING_RAW_LOW": 0,
		"servermain.TAG_SCALING_RAW_HIGH": 14000,
		"servermain.TAG_SCALING_SCALED_DATA_TYPE": 8,
		"servermain.TAG_SCALING_SCALED_LOW": 0,
		"servermain.TAG_SCALING_SCALED_HIGH": 1400,
		"servermain.TAG_SCALING_CLAMP_LOW": false,
		"servermain.TAG_SCALING_CLAMP_HIGH": false,
		"servermain.TAG_SCALING_NEGATE_VALUE": false,
		"servermain.TAG_SCALING_UNITS": "W/m^2"
	}
]


My Apologize for the lack of initial information.

I think your dataset subscript is malformed. I think it should be {dataset}[row, col] all inside the one set of square brackets: Expression Language and Syntax - Ignition User Manual 8.1 - Ignition Documentation
Also, you can use a column name to make things a bit more explicit and maintainable in the future (if your JSON response ever ends up in a different order, it’ll be less fragile).

Some general troubleshooting things to try if that isn’t it:

  1. Right click the component and ‘Run Diagnostics’ - that will confirm what properties are returning that error quality. A type coercion error is pretty unusual for a string typed property - basically everything in Java can be coerced to some string representation via Object.toString().

  2. Wrap your expression in the try function and return some sentinel value to confirm it’s the actual source of the problem. I asked about the source of the value because in some scenarios, a binding will start up with a default (null) value for a custom property, then evaluate your binding to deliver the real value - which can cause temporary errors during window startup, for instance.

You are exactly right! the dataset subscript was incorrect. I was trying to use python syntax but of course that wasn’t working in the Expression Language.

Thank you very much for taking the time to read through and reply to my questions.