Multiple repeating SubForms binding to the same data node | Community
Skip to main content
February 28, 2013
Question

Multiple repeating SubForms binding to the same data node

  • February 28, 2013
  • 14 replies
  • 14297 views

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!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

14 replies

February 28, 2013

"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.

Level 9
March 1, 2013

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

March 1, 2013

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.

March 8, 2013

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

Level 9
March 8, 2013

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

March 13, 2013

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

Level 9
March 13, 2013

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

Level 4
March 13, 2013

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

Level 9
March 13, 2013

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

March 27, 2013

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

Thanks,