Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Multiple repeating SubForms binding to the same data node

Avatar

Former Community Member

Having multiple repeating SubForms binding to the same data node : In our documents, many times we need to display information from same table in multiple locations. For example, if document displays information of Insureds on one page and information of drivers on another page, we need to create a LiveCycle document with two SubForms. Each SubForm needs to have a repeating binding to CommonInsured element in XSD.  LiveCycle Designer is not able to handle such case. We cannot have two subforms bound to the same node, ONLY in a case where repeating option is selected for data binding.

The only way I have found out is the following Javascript

//Get the data node from XML. You will find the code for this function in //JavaHelperFunctions library.

// InsuredDataRepeatingSubForm is a second subform.

//You need to manually add instances to this subform at the

//runtime and Insured data to each instance.

var insuArray = JavaHelperFunctions.getInsureds();

    var i=0;

    for( i=0; i<insuArray.length; i++)

    {

       if (i>0)

       {

var thesubform = this.InsuredDataRepeatingSubForm.instanceManager.addInstance(i);

              thesubform.InsuredName.rawValue = insuArray[i].fullName.value;

       }  

       else

       {

               this.InsuredDataRepeatingSubForm.InsuredName.rawValue = insuArray[i].fullName.value;

       }

    }

Is there any way I can achieve directly using bindings since we are trying to minimize javascript that changes the layout of the form?

Thanks in advance!

14 Replies

Avatar

Former Community Member

"Is there any way I can achieve directly using bindings since we are trying to minimize javascript that changes the layout of the form?"

Yes. Have you created a Schema, data connection to it and bound your form elements? If you bind two elements to the same item in the data connection, when you change one, the other changes.

Avatar

Level 8

Unfortunately not. I've spent countless hours/days trying to do the same thing. You have to use code. The form consumes all the data it can into the repeating elements until there is none left and it is not reused.

Here's a function I wrote just for that purpose. Feel free to use it:

function loadData(source,target){

target.setInstances(source.count);//set the target's subform instances to match the source's

for (var a=0;a<source.count;a++){//loop through each subform instance

  var sourceSubform=source.resolveNode(source.name.substr(1)).all.item(a);

  var targetSubform=target.resolveNode(target.name.substr(1)).all.item(a);

  for (var b=0;b<sourceSubform.nodes.length;b++){//loop through the children of each

   if (sourceSubform.nodes.item(b).className=="field" && targetSubform.resolveNode(sourceSubform.nodes.item(b).name)!=null)//check for matching fields

    if (typeof(targetSubform.resolveNode(sourceSubform.nodes.item(b).name).value.exData)=="undefined" ||

     typeof(targetSubform.resolveNode(sourceSubform.nodes.item(b).name).value.exData.body)=="undefined")

     targetSubform.resolveNode(sourceSubform.nodes.item(b).name).rawValue=sourceSubform.nodes.item(b).rawValue;

    else

     targetSubform.resolveNode(sourceSubform.nodes.item(b).name).value.exData.loadXML(sourceSubform.nodes.item(b).value.exData.saveXML(),1,1);

   if (sourceSubform.nodes.item(b).className=="instanceManager" && targetSubform.resolveNode(sourceSubform.nodes.item(b).name)!=null)//check for matching subforms

    loadData(sourceSubform.nodes.item(b),targetSubform.resolveNode(sourceSubform.nodes.item(b).name));

  }

}

}

Just make sure the source and target subform hierarchies are identifal, same name and all. It will recurse down the tree and transfer source fields (rich text and plain) to their sister targets.

Kyle

Avatar

Former Community Member

Thanks for the reply. Atleast gives me re-affirmation that i'm doing the right thing and there is no way to achieve this directly using bindings.

Avatar

Level 1

Kyle,

I wanted to use your code but as I am new to coding I have to ask a very basic question.

I have a repeating table subform which I want to duplicate on a second page.  i.e., I want row1 in the target table subform to be the same as row1 in the source table subform.

Where in the script do I identify the source and target subforms/tables.... 

Would I stop at the Row1 itentifier? i.e.,

var sourceSubform=source.resolveNode(topmostSubform.Page1.WitnessNameSubform.Table3.Row1.name.substr(1)).all.item(a);

I would appreciate any help.  Thank you in advance.  Vanessa

Avatar

Level 8

You need to call the function loadData with the source and target subforms as your parameters. For example, say you have a button that you click that transfers the data. First create a script object and name it myScripts. Copy and paste the function above into it. Then in the click event of the button you would put myScripts.loadData(sourceSubform.Row1,targetSubform.Row1) or whatever the names of your forms may be.

Alternatively you can forget creating a script object and just put the function in the button with that line of script but the purpose of functions are primarily for reuse in other objects.

Hope that makes sense. If it doesn't let me know and I can post a sample. I won't be able to until Monday though.

Kyle

Avatar

Level 1

I set my hierarchies the same except for the page name.... I change them both to ROR but still the same result.

source is

page1.WitnessNameSubform.WitnessTable.Row1

target is

CrossComplaint.WitnessNameSubform.WitnessTable.Row1

All object fields are named exactly the same. (I actually copied the table from page 1 and pasted it to the second page named "CrossComplaint".)

I copied and pasted the function into a script object page called myScripts.

Below is my command line to call the function.

topmostSubform.CrossComplaint.WitnessNameSubform.WitnessHeading.WitnessButton::click - (JavaScript, client)

myScripts.loadData(Page1.WitnessNameSubform.WitnessTable.Row1,CrossComplaint.WitnessNameSubform.WitnessTable.Row1)

I entered data into the source table. Clicked on the button and nothing happens.

Any ideas? Thanks again for your help.

Vanessa

Avatar

Level 8

Oh wow! My bad. I completely forgot that the paramaters have to be instance manager class objects of your subform. (Wrote that function awhile ago).

That means myScripts.loadData(Page1.WitnessNameSubform.WitnessTable._Row1,CrossComplaint.WitnessNameSubform.WitnessTable._Row1).

Sorry for the headache Vanessa.

If you're still having issues I'd be happy to look at your form for you to figure it out.

Kyle

Avatar

Level 4

Hey there,

I answered a similar question a while back. It's safe to ignore everything and just look at the answer Most of it was just me trying to work out what exactly the OP was asking for. Let me know if the linked answer spawns any questions.

- Scott

Avatar

Level 8

Hi Scott,

Ya, that's what I use to do, but with subforms names changing all the time and especially when I have subforms that can have up to 7 repeatable layers in, I decided to buckle down and write a reusable function that didn't require hard coding it each time.

Kyle

Avatar

Level 1

I wanted to let you know it works great. Saved me a lot of trouble and work..

Thanks,

Avatar

Level 1

Kyle,

Glad I found this thread. 

I'm doing essentially the same thing that Vanessa was doing.  Primary difference being that i'm not duplicating a table row, but a subform.

I can only get the function to work partially for me, it adds the same number of instances to the sister page, but doesn't populate those fields with the values. 

Any suggestions on where my issue might be?

Thanks

Avatar

Level 1

Hello Kyle,

I have created a subform with the ability to auto fill information in subsequent fields throughout the form (1 pager). I added an "ADD" button so that it can duplicate the form as many times as necessary for when we are doing bulk-work. The issue that I am having is that all of the information I enter in the first form will auto-populate in all subsequent "added (repeated)" forms.

I would like for each of the "added" subforms to work independently from each other when it comes to "binding", but still have the ability to auto-populate information within each form only.

how can i accomplish this?

PS: i cannot share the template as its copyrighted by my employer.

Thank you so much!!

Jorge

Avatar

Level 10

Hi Jorge,

I'm not sure what you mean by work independently from each other when it comes to "binding", Do you want the details to auto-populate or are you looking for a button to optionally populate the form.

Bruce