Parse Error in Script Transform After List of Dictionaries Manipulation

I have data from a Query Binding being sent as JSON to a script transform. I can run the following in the Script Console successfully.

value = [{"rowindex":0,"projectid":"U8","description":"32 project","plmt":"controller"},
		{"rowindex":1,"projectid":"U9","description":"b project","plmt":"controller"},
		{"rowindex":2,"projectid":"U10","description":"m project","plmt":"controller"}]

rowIndexColumn_ASLIST=[row["rowindex"] for row in value]

projectList=[]

for x in rowIndexColumn_ASLIST:
	projectItem={
		"target":"/"+value[x]["projectid"]+"/0",
		"label":{
			"text":value[x]["description"]
		}, 
		"visible": True, 
		"enabled": True, 
		"showHeader":True
	}
	projectList.append(projectItem)
	projectItem={}

print (projectList)

The result I get is this, which is exactly what I want:

[{'visible': True, 'showHeader': True, 'label': {'text': '32 project'}, 'enabled': True, 'target': '/U8/0'}, 
{'visible': True, 'showHeader': True, 'label': {'text': 'b project'}, 'enabled': True, 'target': '/U9/0'}, 
{'visible': True, 'showHeader': True, 'label': {'text': 'm project'}, 'enabled': True, 'target': '/U10/0'}]

It seemed to be working so I copied the script over to the Binding window, and adjusted a couple lines so I’m pulling in the query’s value instead of defining it and returning ProjectList instead of printing it. In the end, I get the Error_Configuration: Parse Error in Script Transform.

The error seems similar to the one in this post but my script doesn’t modify the value passed in.

ParseError means exactly that: There’s a problem parsing your code.

Post the exact, actual code you have in the script transform here.

rowIndexColumn_ASLIST=[row["rowindex"] for row in value]
	
projectList=[]

for x in rowIndexColumn_ASLIST:
	projectItem={
		"target":"/"+value[x]["projectid"]+"/0",
		"label":{
			"text":value[x]["description"]
		}, 
		"visible": True, 
		"enabled": True, 
		"showHeader":True
	}
	projectList.append(projectItem)
	projectItem={}

return projectList

Hm, nothing obviously wrong with your script. If you hover over the ‘ParseExpression’ error, is any more information displayed in the tooltip?

I’m using version 8.1.15 and I mocked up a Named Query and used your transform code and it seems to be working fine. Check your spacing or indentation maybe?

If you don’t indent properly you might see a Parse Error in the Error_Configuration message.

1 Like

That was it. I wasn’t indented under the def function. Thank you!

2 Likes