# Multiple Instances Program Nodes

**URL:** <https://forum.universal-robots.com/t/multiple-instances-program-nodes/1904>\
**Category:** Java\
**Created:** [April 19, 2018, 6:42pm UTC](https://forum.universal-robots.com/t/multiple-instances-program-nodes/1904 "2018-04-19T18:42:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ocohen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/ocohen/32/2067_2.png) [@ocohen](https://forum.universal-robots.com/u/ocohen)\
**Post date:** [April 19, 2018, 6:42pm UTC](https://forum.universal-robots.com/t/multiple-instances-program-nodes/1904/1 "2018-04-19T18:42:58Z")

</div>

I am currently writing my first URCap, so I might not completley understand how this works.  
I have a program node which accepts a single text input and act accordingly:

> public void openView() {  
> lblJobName.setText(“Enter Job File Name (inc. extension):”);  
> txtJobName.setText(model.get(“JobName”, “jobName.job”));  
> }  
> public void closeView() {  
> model.set(“JobName”, txtJobName.getText());  
> }  
> public boolean isDefined() {  
> return !txtJobName.getText().equals(“”);  
> }  
> public void generateScript(final ScriptWriter writer) {   
> writer.appendLine(getInstallation().getXMLRPCVariable() + “.LoadJob("” + txtJobName.getText() + “")”);  
> }

If I only have one instance of this program node, everything works fine. But if I have two instances - things get weird. Even though the text in the text boxes is different, both nodes write the same line out.  
At first I thought they might be sharing the model object, so i changed generateScript to:

> public void generateScript(final ScriptWriter writer) {   
> writer.appendLine(getInstallation().getXMLRPCVariable() + “.LoadJob("” + model.get(“JobName”, “jobName.job”) + “")”);  
> }

and now it seems to work fine. Except that if one of the nodes becomes undefined (by setting the txt box to “”) both show up as yellow in the program tree.

Is there something I’m missing about this?

---

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [April 23, 2018, 2:16pm UTC](https://forum.universal-robots.com/t/multiple-instances-program-nodes/1904/2 "2018-04-23T14:16:50Z")

</div>

You should use the DataModel object to store your values.  
There is only 1 instance of the UI, so if you have multiple program nodes, you will experience a “ghosting” between the nodes - since what was entered in a previous node, will also be shown in the UI when navigating to the next one.

So you should implement a callback for the UI interaction to read the value of e.g. a textfield, and store this in the DataModel. And use the DataModel to retrieve the value when generating script or loading the UI on openView.  
This is also the method demonstrated in the HelloWorld URCap for generating the HelloWorld popup.

---

<div class="post-metadata">

**Author:** ![m.birkholz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/m.birkholz/32/7084_2.png) [@m.birkholz](https://forum.universal-robots.com/u/m.birkholz)\
**Post date:** [April 26, 2018, 6:51am UTC](https://forum.universal-robots.com/t/multiple-instances-program-nodes/1904/3 "2018-04-26T06:51:02Z")

</div>

i came up to the same issue. is there a way to store objects rather than primitive data types with the model setter/getter methods?

---

<div class="post-metadata">

**Author:** ![ocohen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/ocohen/32/2067_2.png) [@ocohen](https://forum.universal-robots.com/u/ocohen)\
**Post date:** [April 27, 2018, 2:51pm UTC](https://forum.universal-robots.com/t/multiple-instances-program-nodes/1904/4 "2018-04-27T14:51:18Z")

</div>

Thanks Jacob for your reply,  
The “ghosting” creates a weird bug: Say i have 2 “Comment” nodes, I view the first one and enter some text to the text field. I need to press “submit” on the keyboard for this text to be saved.  
If instead of pressing submit I switch to the second Comment node, the text will be saved in the 2nd one.  
Do you know about this issue? It’s not a critical bug, but is kind of confusing.

(of course the same thing happens if I have 2 instances of the same URCap node)

---

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [May 1, 2018, 9:44am UTC](https://forum.universal-robots.com/t/multiple-instances-program-nodes/1904/5 "2018-05-01T09:44:37Z")

</div>

@ocohen  
I am not able to re-produce the behavior of the Comment nodes.  
When I switch views to another Comment-command, the text is automatically submitted to the original node in focus.  
What software version did you experience this on?

---

<div class="post-metadata">

**Author:** ![anon43302037](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@anon43302037](https://forum.universal-robots.com/u/anon43302037)\
**Post date:** [February 14, 2019, 10:00pm UTC](https://forum.universal-robots.com/t/multiple-instances-program-nodes/1904/6 "2019-02-14T22:00:21Z")

</div>

Could you solved it? I’m having the same problem and I don’t know why the data is being shared, since it must not be.

---

<div class="post-metadata">

**Author:** ![ocohen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/ocohen/32/2067_2.png) [@ocohen](https://forum.universal-robots.com/u/ocohen)\
**Post date:** [December 9, 2020, 11:38pm UTC](https://forum.universal-robots.com/t/multiple-instances-program-nodes/1904/7 "2020-12-09T23:38:33Z")

</div>

@jbm I am seeing this problem again, I reproduced it with comments in the same way I explained earlier.

For some reason this bug does not happen if there is a space in the comment (might be other criteria as well)

 ![P7cgfb1Ifu](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/9/91f2b055ca8dda80d929e6ad7f22a7d5af000a80.gif)

---

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [December 10, 2020, 8:58am UTC](https://forum.universal-robots.com/t/multiple-instances-program-nodes/1904/8 "2020-12-10T08:58:54Z")

</div>

Thanks, @ocohen  
We fixed it, but seems it’s back and we are able to reproduce.  
Thanks for reporting.
