Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

SubForm with data binding that repeats

Avatar

Former Community Member

Hello,

I have a subform that is bound to a node in XSD which will have mutilate occurrences at runtime. The subform has just one textfield which prints the name of such item. My form has three pages and I need to use this same subform on Page 1 and Page2. Problem is that it works on Page1 but does not work on Page 2.

Form is designed as follows"

Page1SubForm

-- RepeatingNodeSubform

Page2SubForm

-- RepeatingNodeSubform.

XML is as follows

<Employee>

     <Name> XXX </Name>

     <SSN></SSN>

     <DOB></DOB>

</Employee>

<Employee>

     <Name> YYY</Name>

     <SSN></SSN>

     <DOB></DOB>

</Employee>

RepeatingNodeSubform on Page1 works fine but on page2 does not display anything. If bound to another repeating node, it works on Page2.

What could be an issue? Also, is there any restriction such as on the same form there can not be two subforms bound to the same node?

Thanks in advance!

1 Accepted Solution

Avatar

Correct answer by
Level 4

Hey again,

Sorry for the delay in getting back to you; I had to wait for my break.

Alright, from everything you've said, I seems to me that your only real option would be to use some code to copy the values from page one to all of the other pages. Seeing as your users won't be making any changes and you will just be doing data bindings, I would suggest either making all of your fields read-only, or possibly printing to a virtual pdf printer once you've imported the date in order to 'flatten' your pdfs before sending them to your users... this is to prevent them from accidentally making changes.

Alright, so I've made the following assumptions:

- The repeatable subform on page one and page two are exact duplicates of one another. All fields and subforms use the same names, and the only difference between them is that one is on page1 and the other is on page2.

- This means that the som for two are the same except for the page. i.e.: the som to the Name field on the first page is:

EmployeeInformation.page1.Employee.Name

and that the som for the name field on the second page is:

EmployeeInformation.page2.Employee.Name

If this is the case, then you need to add the following scripts to make the import also trigger the copy to the other instance of the table:

in the page2 initialize event, add:

_Employee.setInstances(page1._Employee.count);

The above will add as many blank rows to the repeatable subform on page two as needed to include all of the records from page one. Then in each field on the second page's repeatable subform, in the initialize event put:

this.rawValue = xfa.form.resolveNode(this.somExpression.replace("page2","page1")).rawValue;

The above code looks for a field on page 1 that exactly matches the some expression of the current field (aside from the page being called page1 instead of page2), and copies the value of the field to itself.

I've tested it in a form I just made and it's working fine on my end.

let me know if you need any further instructions, or if your form uses different names for the pages, aside from page1 and page2.

I have to run as my break is ending soon. Best of luck,

- Scott

View solution in original post

9 Replies

Avatar

Level 4

Hi,

I was about to blindly say that you had to use unique names for all subforms, when I realized that I had never tried to see what happens when you didn't. I built a very simple test form, and used two repeatable subforms with the same name. I opened the form input a number of records in each repeatable subform, then exported the data as xml:

        <sf_container_person>

            <sf_repeatable>

                <TextField1>1</TextField1>

                <TextField2>2</TextField2>

                <DateTimeField1>3</DateTimeField1>

            </sf_repeatable>

            <sf_repeatable>

                <TextField1>4</TextField1>

                <TextField2>5</TextField2>

                <DateTimeField1>6</DateTimeField1>

            </sf_repeatable>

        </sf_container_person>

        <sf_container_person>

            <sf_repeatable>

                <TextField1>7</TextField1>

                <TextField2>8</TextField2>

                <DateTimeField1>9</DateTimeField1>

            </sf_repeatable>

            <sf_repeatable>

                <TextField1>10</TextField1>

                <TextField2>11</TextField2>

                <DateTimeField1>12</DateTimeField1>

            </sf_repeatable>

        </sf_container_person>

When I bound the data back to the form, everything was filled in as it should have been. I guess this means that it is possible to have the same names for different subforms and still have it auto-magically work. Still, even just to test this out, my mind was screaming at me to give the subforms unique names. I half-expected the fabric of reality to be torn asunder when I imported the data back into the form =P

If you can, I would strongly suggest using unique names for all subforms. It just takes a lot of the guesswork out of what will end up where.

If that isn't an option, would you be able to post your form for us to look at? I can't say what is going on without seeing it first. I would also suggest opening your form, filling it out manually, then exporting the data from the form to see the structure of the xml that your data is expecting. Unless you have set your pages to use no data bindings, it could be that your second subform is expecting to be within a page2 element of some kind:

<form1>

   <page1>

      <Employee>

           <Name> YYY</Name>

           <SSN></SSN>

           <DOB></DOB>

      </Employee>

   </page1>

   <page2>

      <Employee>

           <Name> YYY</Name>

           <SSN></SSN>

           <DOB></DOB>

      </Employee>

   </page2>

</form1>

...or something similar, and that binding to similar names subforms across different pages excludes the page level of the xml heirarchy. Who knows? But looking at the format of the data that your form spits out should help you see what format it expects to recieve data in.

I know this isn't a straight-forward answer, but without seeing your form, I can only make educated guesses. good luck, and let me know how it goes,

- Scott

Avatar

Former Community Member

Thank you Scott!

I did a lot of research over the weekend and it seems like binding one repeatable nodeset to multiple subforms on one form is not supported by Adobe! Here's one such discussion for example:

http://acrobatusers.com/forum/forms-livecycle-designer/bind-same-nodeset-multiple-subforms#comment-f...

Couple of points regarding my post - I don't have any restriction of having the same form names. The names are in fact different but it still did not work for me. I am not able to post my form due to confidentiality reasons (the form, the XSD etc are proprietary and I am not allowed to disclose the info). If absolutely required I can cook up a form with sample data by the end of this week (I have a deadline to meet before that).

Its really great you have gotten it to work. Would you be able to attach your sample form that works with repeatable node set instead? I couldn't believe when I got to know that Adobe doesn't support it. It almost seems like a glaring defect to me.

Thanks again for your response, I am very curious to see your working form as this is one of the main requirements that we have.

Avatar

Level 4

Hey there,

I deleted the sample that I built yesterday, and I don't have the time to build a new one today. I can, however, tell you how I got it to work:

Your xml  is as follows:

<Employee>

     <Name> XXX </Name>

     <SSN></SSN>

     <DOB></DOB>

</Employee>

<Employee>

     <Name> YYY</Name>

     <SSN></SSN>

     <DOB></DOB>

</Employee>

I assume that you want XXX on page1 and YYY on page 2... additionally, I assume that each page can have multple employee elements bound to them... hense the repeatable subform with the name field. The issue that you're seeing is that Adobe has no way of grouping which employee elements go together. In your XML, it looks like both employee elements are siblings. You need to add a parent element to the xml that groups the particular elements together. the data from my form looked like:

<?xml version="1.0" encoding="UTF-8"?>

<EmployeeInformation>

    <Employees>

        <Employee>

            <Name>Sur1.1</Name>

            <SSN>SNN1.1</SSN>

            <DOB>DOB1.1</DOB>

        </Employee>

        <Employee>

            <Name>Sur1.2</Name>

            <SSN>SNN1.2</SSN>

            <DOB>DOB1.2</DOB>

        </Employee>

        <Employee>

            <Name>Sur1.3</Name>

            <SSN>SNN1.3</SSN>

            <DOB>DOB1.3</DOB>

        </Employee>

    </Employees>

    <Employees>

        <Employee>

            <Name>Sur2.1</Name>

            <SSN>SNN2.1</SSN>

            <DOB>DOB2.1</DOB>

        </Employee>

        <Employee>

            <Name>Sur2.2</Name>

            <SSN>SNN2.2</SSN>

            <DOB>DOB2.2</DOB>

        </Employee>

    </Employees>

</EmployeeInformation>

In my form, I changed the form name to EmployeeInformation, giving me the root element... I named both page 1 and page 2 to Employees (note the 's' at the end), giving me a parent element for the actual Employee (no 's') element. Each page had a repeating subform called employee. All other subforms had their databindings set to 'no data binding'.

As you can see, my XML has two sets of employee data, each contained within an 'Employees' parent. Adobe sees this, then binds the first instance of employees to the first repeatable subform, and binds the second to the second.

So, yes, the subforms and pages had the sme name, but it still required some way to determine which elements went to which page.

As you've pointed out, though, this is not the intended use, and I can easily see Adobe mixing up the 'page' order of the data for the two repeating subforms. Without unique names, you can only cross your fingers and hope that the pdf binds correctly.

Where are you getting your data from? Is there any way that you can transform the data before binding it to your form. If you can, then you can restructure the data to use unique names, then create your form to use these unique names. It would prove to be a whole lot more stable in the long run.

- Scott

Avatar

Former Community Member

Thanks Scott.

Let me clarify  - I want all the employee data on different pages. It is not XXX on page 1 and YYY on page2. Based on your example: I want PDf to render like like the tables below.

Hence, I do not want the Employees node there. Lets call my subform for Page1 as Page1SubForm and subform pn Page2 as Page2SubForm. And imagine your XML with 5 Employee nodes within EmployeeInformation tag (lets remove Employees tab as I do not need to group the employee). I have databinding for Page1SubForm as EmployeeInformation.Employee[*]  and also for

Page2SubForm as EmployeeInformation.Employee[*]  and three text fields form Name, SSN and DOB in one row in each subform. I expect these to repeat for each employee. It works great for PageSubForm1 but doesn't work at all for PageSubForm2.

I think the difference between your and my example is that I was ALL the data to repeat in different pages not sections of data as you have assumed.

Page1

Employee Data

Name

SSN

DOB

Sur1.1

SSN1.1

DOB1.1

Sur1.2

SSN1.2

DOB1.2

Sur1.3

SSN1.3

DOB1.3

Sur2.1

SSN2.1

DOB2.3

Sur2.1

SSN2.2

DOB2.3

Page2

Employee Data

Name

SSN

DOB

Sur1.1

SSN1.1

DOB1.1

Sur1.2

SSN1.2

DOB1.2

Sur1.3

SSN1.3

DOB1.3

Sur2.1

SSN2.1

DOB2.3

Sur2.1

SSN2.2

DOB2.3

Avatar

Level 4

Hey again,

I can see how this could be difficult to achieve. I have a few ideas, but it really depends on a number of things:

- Is it just the two pages, or is the number of pages dynamic? If it is dynamic, what determines how many pages are to be included?

- What sets the two pages apart from one another? Are they exactly the same as one another, or are there other fields asides from the repeating subform the set page 1 apart from page 2?

- Is this form just intended to have it's data bound to it, or will users be filling it in? If users are to fill it in as well, will you allow them to make changes to the duplicated information? If so, are their changes supposed to reflect on both pages, or just where they made the change themselves.

- how much control of the structure of the source data do you have? Can you make alterations to the xml schema, or are you stuck using what you are given?

Sorry for the avalanche of questions... it's just hard to help without knowing exactly what you're trying to acheive.

- Scott

Avatar

Former Community Member

Thanks much scott! Very insightful questions indeed. The answers are inline in bold.

- Is it just the two pages, or is the number of pages dynamic? If it is dynamic, what determines how many pages are to be included?

The no. of pages are dynamic. Page 1 is static page but Page 2 can be repeated based on the data. What controls this number is another outer subform and the data binding based off of another nodeset to that subform.

- What sets the two pages apart from one another? Are they exactly the same as one another, or are there other fields asides from the repeating subform the set page 1 apart from page 2?

Pages are different, other fields on the page are different aside from the repeating subform.

- Is this form just intended to have it's data bound to it, or will users be filling it in? If users are to fill it in as well, will you allow them to make changes to the duplicated information? If so, are their changes supposed to reflect on both pages, or just where they made the change themselves.

The form is static, users do not fill anything. They just see the final laid out data on the form. So for the users it is essentially a PDF read-only document

- how much control of the structure of the source data do you have? Can you make alterations to the xml schema, or are you stuck using what you are given?

I can make the alterations to the XML schema.

Avatar

Correct answer by
Level 4

Hey again,

Sorry for the delay in getting back to you; I had to wait for my break.

Alright, from everything you've said, I seems to me that your only real option would be to use some code to copy the values from page one to all of the other pages. Seeing as your users won't be making any changes and you will just be doing data bindings, I would suggest either making all of your fields read-only, or possibly printing to a virtual pdf printer once you've imported the date in order to 'flatten' your pdfs before sending them to your users... this is to prevent them from accidentally making changes.

Alright, so I've made the following assumptions:

- The repeatable subform on page one and page two are exact duplicates of one another. All fields and subforms use the same names, and the only difference between them is that one is on page1 and the other is on page2.

- This means that the som for two are the same except for the page. i.e.: the som to the Name field on the first page is:

EmployeeInformation.page1.Employee.Name

and that the som for the name field on the second page is:

EmployeeInformation.page2.Employee.Name

If this is the case, then you need to add the following scripts to make the import also trigger the copy to the other instance of the table:

in the page2 initialize event, add:

_Employee.setInstances(page1._Employee.count);

The above will add as many blank rows to the repeatable subform on page two as needed to include all of the records from page one. Then in each field on the second page's repeatable subform, in the initialize event put:

this.rawValue = xfa.form.resolveNode(this.somExpression.replace("page2","page1")).rawValue;

The above code looks for a field on page 1 that exactly matches the some expression of the current field (aside from the page being called page1 instead of page2), and copies the value of the field to itself.

I've tested it in a form I just made and it's working fine on my end.

let me know if you need any further instructions, or if your form uses different names for the pages, aside from page1 and page2.

I have to run as my break is ending soon. Best of luck,

- Scott

Avatar

Former Community Member

Thank you very much Scott!

I had done scripting to populate the second form but it was around 10+ lines on code and was very ugly. This is a very elegant solution. Thanks much for your effort of creating and testing such forms for us. This type of question was asked a few times before and hopefully going forward all of us will have to-the-point answer to refer to!

Avatar

Level 2

Hi Scott,

This is exactly what I want my Form looks something like below, the French subform is an exact duplicate of the english subform. The ItemBody subform is the repeating subform it works Ok in the first page but in the second page cannot see the items.

Form Overview2.jpg

My XML is something like below

<Invoice>

          <InvoiceHeader>

          </InvoiceHeader>

          <InvoiceDetail>

                         <ListOfInvoiceItemDetail>

                                        <InvoiceItemDetail>

                                                       <InvoiceBaseItemDetail>

                                                                      <LineItemNum>

                                                                                     <BuyerLineItemNum>1</BuyerLineItemNum>

                           <SellerLineItemNum>1</SellerLineItemNum>

                                                                      </LineItemNum>

                                                       </InvoiceBaseItemDetail>

                                        </InvoiceItemDetail>

            <InvoiceItemDetail>

                 <InvoiceBaseItemDetail>

                      <LineItemNum>

                           <BuyerLineItemNum>2</BuyerLineItemNum>

                           <SellerLineItemNum>2</SellerLineItemNum>

                      </LineItemNum>

                 </InvoiceBaseItemDetail>

             </InvoiceItemDetail>

  <InvoiceSummary>

          </InvoiceSummary>

</Invoice>

The Binding I have in the first occurence of Subform ItemBody is InvoiceDetail.ListOfInvoiceItemDetail.InvoiceItemDetail[*] which works perfectly fine. But when trying to initialise the instance for second occurence of subform ItemBody with commands below none of them seem to work.

_ItemBody.setInstances(5); or _ItemBody.setInstances(_ItemBody.count);

I am leaving the binding as none in this case. Can you please suggest the script commands to get this working.

Regards,

Harry