Moving table data to gateway scope tags

Here is a piece of the code we are using to move table data to gateway scoped tags. What we are looking for is there a better way to move the data. I have just started to use any kind of scripting so I am looking for any guidance to move this data efficiently. In total we are moving about 100 pieces of data to different tags in different folders. This piece of the code works, but at this point we only have 18 pieces that we are testing.

Pull the dataset property off a Table component

data = event.source.parent.getComponent(‘Power Table_Create’).data

idx = data.rowCount
for row in range(data.rowCount):

results = data.getValueAt(row, "Value")
if idx == 18:
	system.tag.write("ExtRecipe/Barrel/BZ1",results)
elif idx == 17:
	system.tag.write("ExtRecipe/Barrel/BZ2",results)
elif idx == 16:
	system.tag.write("ExtRecipe/Barrel/BZ3",results)
elif idx == 15:
	system.tag.write("ExtRecipe/Barrel/BZ4",results)
elif idx == 14:
	system.tag.write("ExtRecipe/Barrel/BZ5",results)
elif idx == 13:
	system.tag.write("ExtRecipe/Barrel/BZ6",results)
elif idx == 12:
	system.tag.write("ExtRecipe/Barrel/BZ7",results)
elif idx == 11:
	system.tag.write("ExtRecipe/Barrel/BZ8",results)																			
print results, idx
idx -=1

There’s a number of things to address here, but it would be easiest if you showed us your query and the database structure behind it, and summarized what you are trying to achieve. Using ‘if/elif/else’ constructs like you’ve shown won’t scale well, as you probably realized. Also, when pasting scripts into the forum, be sure to use the ‘code’ button in the toolbar, so we can see the indentation properly.

This small project is try to allow users to set up a machine run profile to create a recipe to insert/ update a table in the data base. We are using tags to transfer information to a transaction group that does the inset/update, but we are trying to use the client as a temporary storage for the information. The information is entered through numeric text field, text fields and text area inputs. There is lots of information so the display is broken into areas of the machine to make it easier for the user to enter information. We thought about writing directly to the tags but the issue is there could be up to 3 to 4 users updating/creating the recipes. One solution we came up with was to use a cell update in the table to generate the information that could be passed to the tags once the update/create was completed. We are trying to figure out an efficient way of transferring the data or if there is a better way to do accomplish the task.

Here is the code we are looking at to transfer the data from the table to the tags. Any help would be appreciated.

# Pull the dataset property off a Table component
data = event.source.parent.getComponent('Power Table_Create').data

idx = data.rowCount
for row in range(data.rowCount):
	
	results = data.getValueAt(row, "Value")
	if idx == 18:
		system.tag.write("ExtRecipe/Barrel/BZ1",results)
	elif idx == 17:
		system.tag.write("ExtRecipe/Barrel/BZ2",results)
	elif idx == 16:
		system.tag.write("ExtRecipe/Barrel/BZ3",results)
	elif idx == 15:
		system.tag.write("ExtRecipe/Barrel/BZ4",results)
	elif idx == 14:
		system.tag.write("ExtRecipe/Barrel/BZ5",results)
	elif idx == 13:
		system.tag.write("ExtRecipe/Barrel/BZ6",results)
	elif idx == 12:
		system.tag.write("ExtRecipe/Barrel/BZ7",results)
	elif idx == 11:
		system.tag.write("ExtRecipe/Barrel/BZ8",results)	
	print results, idx
	idx -=1

Here the dataset that we are pulling the information from.

Ok. I personally wouldn’t use tags to route from your operators to your recipe database. I’d use a script that gathers all of the field values in your UI and generates the appropriate call(s) to system.db.runPrepUpdate().
For the specific code you show, I’d rewrite the loop to use system.tag.writeAll() like so:tags = [] values = [] for row in range(data.rowCount): tags.append("ExtRecipe/Barrel/%s" % data.getValueAt(row, 'Name')) values.append(data.getValueAt(row, 'Value')) system.tag.writeAll(tags, values)

I was looking into the system.tag.writeAll() but was not sure how to get the information directed to the correct location from the table. After looking at you script, I now understand how this works. I will look into the system.db.runPrepUpdate() and see if command is something I can get working. Thanks for your help.