I am looking for the correct way to get values from inside a template repeater back out to the parent component. The parent component has a template repeater that displays a template for all the individual UDT's within a folder. Then inside the template which represents each UDT, we have indirect tag references to pull the individual tags. I want to pull a date from the base UDT and pass it back up to the parent component. Overall goal is to do this twice since we have nested templates and repeaters but if its possible at one level it should work for both I think...
Based on some initial research it sounds like it should be possible with System.util.sendMessage. but i'm wondering if there is a more standard way of doing this.
You say "template repeater", which is a Vision component. (You should tag the topic properly.) If so, then a script within a template can traverse outward in the component hierarchy with three .parent.parent.parent references at the template root level. (Also for the template canvas. Just .parent.parent for the singleton template holder.)
If not Vision, you need system.perspective.sendMessage(). (Perspective isolates views from each other. Vision does not isolate anything.)
Thanks for the response, updated the topic tag as well.
I am probably doing it wrong then because when I try and reference a parent property from the template that exists on the template repeater I get
"NameError: name 'parent' is not defined"
Sure, This is the code which sits in the property change script on the template. Essentially just looks to see if the UDT has a valid start date then it tries to write to the ActiveStepDate which is a custom property on the template repeater.
if event.source.getComponent('schedStartlbl').text != "":
event.source.parent.ActiveStepDate = event.source.getComponent('schedStartlbl').text
That doesn't look like a valid propertyChange event script for Vision. You aren't checking the event's propertyName--that is mandatory. Also, please format posted code as code, so indentation is preserved: Wiki - how to post code on this forum.
You don't have enough .parent references to get to an outer object. Also note that there is a quirk of Vision that prevents the proper jython wrapper being applied in this case--the simplest fix for that is to install my Integration Toolkit. Without the fix, a custom property like .ActiveStepDate won't work.
Yeah I am really just trying to prove out the concept so pushing that up one level would work for my testing.
I will double check my code. I think I have used similar scripts on source components that worked. In the notes it indicates that the property change script fires whenever a bindable property of the source component changes which is why I thought this would work as well.
Do you mind linking to your Integration Toolkit? Il take all the help I can get.
Thanks.
I haven't yet gone into your Toolkit but that's my next step.
Just to confirm.
Is the quirk in the vision components here that when you try and move up through the levels you end up stepping outside the normal container structure?
I am now seeing a reference to javax.swing.JViewport when I try and go 3 levels up.
No it is an artifact of Ignition only applying the PyComponentWrapper on selected component functions, so it won't apply to plain Swing object method return values. My toolkit registers a global jython type adapter to catch that flaw.
Use the chain of .parent references to reach the repeater component, rely on my toolkit to ensure its custom props and methods work properly, and manipulate those directly.