Dynamic UDT path in script

Hello all,

I have UDT called order and it includes an orderNo and state value.
The orderNo value is coming from a named query and the return mode is set to JSON, I have a transform script to return the state value of each orderNo but it does not work. It returns null instead of the value:

	list = []
	for i in range(value):
		dict = {
            "id" : i+1,
			"state": system.tag.read("[default]Order/Order"+"id"+"/State"")
			)
		}
		list.append(dict)
	return list

You have quotes around what I presume is intended to be code. Try:

	list = []
	for i in range(value):
		dict = {
			"state": system.tag.read("[default]Order/Order"+self.custom.orderNo[i].order_number+"/State")
			)
		}
		list.append(dict)
	return list
1 Like

That does not work it says cannot concatenate int and str.

I changed my code to:
still does not work

	list = []
	for i in range(value):
		dict = {
            "id" : i+1,
			"state": system.tag.read("[default]Order/Order"+"id"+"/State"")
		}
		list.append(dict)
	return list

self.custom.orderNo[i].order_number is an integer so you must convert it to a string.

	list = []
	for i in range(value):
		dict = {
			"state": system.tag.read("[default]Order/Order" + str(self.custom.orderNo[i].order_number) + "/State")
			)
		}
		list.append(dict)
	return list
1 Like

That worked! Totally forgot about that!!! Thank you so much!!!