Update row in template repeater using button (outside from template) click

Hi Guys,

I'm trying to update the row when clicking on the button. But in my case button is from outside of the template repeater.

Below is a screenshot, for more details.

Any idea how to fix this?


Can you just update the data in the templateParams?
Otherwise, we will need more info on how you're populating the template repeater templateParams and what values you want to update in the row, and how they're populated

@nminchin Thanks for your response.

I have created template parameters in the template and updated button outside of the template repeater..

How are you populating the template repeater's template parameters though?

using dataset.

Below script on radio button.

if event.propertyName == "selected":
	if event.source.selected == 1:
		num = event.source.parent.parent.Nummer
		pyDataSet = system.db.runPrepQuery(query, [num],)
		normalDataset = system.dataset.toDataSet(pyDataSet)
		event.source.parent.getComponent('tmp_Test').templateParams = normalDataset

In the template bind every component to the template parameter.

...so the radio buttons populate the template repeater with All, Fulfilled, or Not Fulfilled from your database depending upon selection. Then this data can then be changed via the text boxes within the the individual templates. What you are actually wanting to do, is get the modified data from the textboxes and run an UPDATE query whenever the Change button in the top right of the window is pressed?

I see a dropdown and two text fields; which components are relevant to the UPDATE query?

@justinedwards.jle thanks for the response.

checkbox, text field, numeric text field, and dropdown these components relevant to the update query.

If your template parameter bindings are bidirectional, you could simply reuse them to build your query arguments. Here is an example script that does this:

repeater = event.source.parent.getComponent('Template Repeater')
for template in repeater.getLoadedTemplates():
	arguments = []
	for customProperty in template.dynamicProps:
	print arguments #use these arguments for your UPDATE query

Edit: replaced getTemplates function with built in method for getting loaded templates


Thanks, @justinedwards.jle

Yes, All parameter bindings are bidirectional. I will try this script.

@justinedwards.jle Thank you so much.

Work perfectly!!

1 Like

@justinedwards.jle sorry for the inconvenience.

Only the dropdown value is not updated. remaining all component values updated successfully.

I select the dropdown value but do not set the new value in the database. updated old value.

I would double check the binding to make sure it's bidirectionallly bound to a custom template parameter. If it's not or can't be, then we'll have to loop through the template components and get the selectedStringValue from the dropdown.

Here is a script that will get the relevant dropdown values from each template:

from com.inductiveautomation.factorypmi.application.components import PMIComboBox
repeater = event.source.parent.getComponent('Template Repeater')
for template in repeater.getLoadedTemplates():
	arguments = []
	for component in template.getComponents():
		if isinstance(component, PMIComboBox):
			print component.selectedValue
			print component.selectedLabel
			print component.selectedStringValue

Note: This script replaces the getTemplates function I had originally developed with a built in method for getting the loaded templates. Since I believe this to be the correct approach, I refactored the original script in my previous post to use this method.

That said, I set up a test with dropdowns that were bidirectionally bound to template parameters, and I couldn't recreate the problem. The values extracted from the template repeater matched the changes I had made to the dropdown:


[False, 42, u'Fulfilled', u'Mess for Testing']
[True, 44, u'Fulfilled', u'Subsequent Mess for Testing']
[False, 45, u'Not Fulfilled', u'Some string that is needed specifically for testing']
[True, 47, u'Fulfilled', u'Some other string that is needed specifically for testing']
[True, 49, u'Fulfilled', u'Yet ANOTHER that is needed specifically for testing']
[False, 50, u'Not Fulfilled', u'FINAL string that is needed specifically for testing']

Original Dataset:

My guess is that the parameter is missing or is not bidirectionally bound, or perhaps it is somehow missing from the UPDATE query.

1 Like

@justinedwards.jle Thank you for your support.

I will check.

@justinedwards.jle Thank you so much.

Resolved my issue. I'm binding the custom property in the dropdown the wrong way. Now worked perfectly.

1 Like