Expand my Community achievements bar.

SOLVED

Copy to new instance of subform

Avatar

Level 2

What I am looking to do is to copy a field and when a new instance of a subform is created past it to another field.

When a user clicks the transmit button, the transmit button opens a new instance of the form.  I need the Sent To field to populate the Reviewer field on the new instance.  Is this a possibility?

instance.png

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Here is an example:

https://acrobat.com/#d=HD6XJ1qofZDf713Yq1P43g

The first example just sets the value of the dropdown. The second adds an item to the Reviewer dropdown, as the Send to dropdown allows custom entry.

I'm been lazy though as the script should check for duplicates first. I'll try and get back to this.

Hope that helps,

Niall

Assure Dynamics

View solution in original post

10 Replies

Avatar

Level 10

Hi,

When you say another instance of the form, do you mean a new instance of the subform within the XFA form?

If this is the case then yes it is possible with a bit of scripting.

You would basically need to count the number of instances and then resolve the nodes for the objects in the two instances.

// script to add instance of subform

// count the number of instances zero based numbering

var lastRow = _mySubform.count - 1;

var 2ndLastRow = lastRow - 1;

xfa.resolveNode("mySubform[" + lastRow + "]").reviewer.rawValue = xfa.resolveNode("mySubform[" + 2ndLastRow + "]").sentTo.rawValue;

You will need to change the references to reflect your form and it may need a bit of tweaking to get it working.

Niall

Assure Dynamics

Avatar

Former Community Member

You want to append the name from the Send To drop-down list to the Receiver drop-down list?

Steve

Avatar

Level 2

Steve

Just to be clear, only on the new instance of the subform, if that's what you were indicating then you are correct.  we're trying to automate as much possible, and to prevent user error.

Avatar

Level 10

Good catch Steve!!!

"More haste less speed"

Niall

Avatar

Level 10

Hi,

This should add an new item to the reviewer dropdown and set its rawValue:

// script to add instance of subform

// count the number of instances zero based numbering

var lastRow = _mySubform.count - 1;

var 2ndLastRow = lastRow - 1;

var oItem = xfa.resolveNode("mySubform[" + 2ndLastRow + "]").sentTo.rawValue;

// add the item to the dropdown

xfa.resolveNode("mySubform[" + lastRow + "]").reviewer.addItem(oItem);


// set the rawValue

xfa.resolveNode("mySubform[" + lastRow + "]").reviewer.rawValue = oItem; 

However this won't check for duplicates. Steve has a good script for this: Drop-down list automatic add-on

Good luck,

Niall

Assure Dynamics

Avatar

Former Community Member

I created and attached a sample, albeit more complicated than Niall's suggestion.

Steve

Avatar

Level 2

Steve,

I have reviewed your example that you supplied and I don't that I explained in enough detail, because what you did was great.  There is on small piece that I'm looking for the form to do, I'll try to better explain it.  After you select the Reviewer and Send To fields, and click the add button,  What I was hoping for was that the second instance would prepopulate the reviewer with the name from the Send To field from the previous instance.  Thanks again for all of your help.

Avatar

Level 2

Niall,

Thanks for all you assistance.  I was trying to implement your example in my script, but I wasn't able to figure out where in my script that the items went. If you could provide some more direction it would be greatly appreciated.  Thanks.

Avatar

Correct answer by
Level 10

Hi,

Here is an example:

https://acrobat.com/#d=HD6XJ1qofZDf713Yq1P43g

The first example just sets the value of the dropdown. The second adds an item to the Reviewer dropdown, as the Send to dropdown allows custom entry.

I'm been lazy though as the script should check for duplicates first. I'll try and get back to this.

Hope that helps,

Niall

Assure Dynamics

Avatar

Level 2

Niall and Steve

I don't know how to thank you enough for all the assistance that you provided.  With all of the assistance I've gotten from this site I can finally put this form to bed!  Have a great weekend.