Expand my Community achievements bar.

SOLVED

Question about scripts in repeatbel sub-form objects

Avatar

Employee

Hi,

  I am working on creating a form which has a sub-form that can be repeated as many times as the user wants to. There is an ‘Add’ button which creates an instance of the sub-form on the form, when clicked.

On the sub-form I have 5 numeric fields say a1-a5 and 1 field say b1 which is the sum of all these 5 fields.

On the Main form I have a 2 fields - say t1 and f1.

The requirement is t1=f1+b1+(sub-form instance 2’s b1)+(sub-form instance 3’s b1)+ and so on …depending on as many sub-form instances there are that the user adds.

I have created Actions using the Action Builder such that when any of a1 to a5 fields are exited, b1 will be updated with the sum of a1-a5. At the same time t1 will be updated with sum of f1 and b1.

This works great for 1 instance of the sub-form. But when ‘Add’ is clicked and a second instance of the sub-form is added, then the script does not work as it did for the first instance of the sub-form. So for any instances of the sub-form added, when values are added to a1-a5 and the fields are existed, b1 does not get updated.

How can I fix this?

See attached form that I am creating for clarity.

‘Total Hours worked this week’ is the t1 I was talking about. See how it gets updated when values are entered in any of the hour fields. It works fine with the default instance of the T100/Strategic/Advantage Customer Information sub-form as well. But when I click on ‘Add Customer’ button to add another instance of the sub-form, it does not work as expected.

Please let me know if it is still not clear and I can explain the issue.

1 Accepted Solution

Avatar

Correct answer by
Level 5

Hi Ameeth,

Please find below link which has your document.

https://workspaces.acrobat.com/?d=OEkwisQ99LXgJ4e9GrCnZg

Hope this works fine..

I am not sure why you created those functions?

Let me know if you need any clarification.

Thanks

Vjay

View solution in original post

4 Replies

Avatar

Correct answer by
Level 5

Hi Ameeth,

Please find below link which has your document.

https://workspaces.acrobat.com/?d=OEkwisQ99LXgJ4e9GrCnZg

Hope this works fine..

I am not sure why you created those functions?

Let me know if you need any clarification.

Thanks

Vjay

Avatar

Level 3

Vjay's solution works great! Essentially, take out all of your other programming on the individual fields, and hard script the field you want the sum to show on. By directly referencing the fields, Adobe is able to tell the difference between one instance and another and doesn't get them mixed up. (I have found for some of these dynamic functions, the Action Builder doesn't really work, so you need to code by hand)

My only suggestion, would be to perhaps modify Vjay's code a little, and use Javascript instead of Formcalc. We have run into the problem where if a user is using the form from a webserver or something and hasn't actually been saved to the user PC, the Formcalc scripts won't run, only Javascript. But it all depends on how you are using your forms.

Here is your line of code changed to Javascript, in case you want to make that change. (there's really not much difference at all)

this.rawValue = sum(CustomerTimeBD.Row1.Cell1.rawValue + CustomerTimeBD.Row1.Cell2.rawValue + CustomerTimeBD.Row2.Cell1.rawValue + CustomerTimeBD.Row2.Cell2.rawValue + CustomerTimeBD.Row3.Cell1.rawValue + CustomerTimeBD.Row3.Cell2.rawValue + CustomerTimeBD.Row4.Cell1.rawValue + CustomerTimeBD.Row4.Cell2.rawValue + CustomerTimeBD.Row5.Cell1.rawValue);

Avatar

Level 5

Actually i had written it in Javascript then i thought it is simple summing so i did it in FormCalc.

Good thing is it is working ..

Vjay

Avatar

Employee

Vijay - Thanks for the solution. It works perfectly.

GeneveveX - thanks for the JS

cheers.

Ameeth