Script transform giving ScriptEval errors with seemingly valid dictionary manipulation

I have data from a Query Binding being sent as JSON to a script transform and the data looks like this:

[ { 'source': 'beginning:end', 'count': 5}, 
  { 'source': 'beginning2:end2', 'count': 10}]

My goal is to get it to look like this:

[ { 'source': 'end', 'count': 5}, 
  { 'source': 'end2', 'count': 10}]

And I’m using the following script transform code within the transform function to try to accomplish this:

for x in value:
	x['source'] = x['source'].split(':')[-1]

return value

I’ve tested this in the Scripting Console, in online REPLs and this code does exactly what I want. However, I always get Error_ScriptEval in the Binding Preview when trying to actually use this code as a script transform.

I’m stumped, any ideas as to what is going wrong here?

You can’t modify the value passed in.

	newValues = []
	for x in value:
		newValue = {}
		for k, v in x.iteritems():
			if k == "source":
				newValue[k] = v.split(':')[-1]
			else:
				newValue[k] = v
		
		newValues.append(newValue)
	
	return newValues
3 Likes

Well that explains it, and fixed the problem. Thank you!

I ran into the same issue but then I found that It's important to note that the dataset passed to the script is an Ignition dataset, which is immutable and presented as an enumerator. To manipulate the data, you need to convert it to a PyDataset using the system.dataset.toPyDataSet(value) function. This conversion allows you to work with the data in a more flexible format, enabling you to perform any desired manipulations. I hope this clears up things for someone else.

Same reply as I made over here: