Expand my Community achievements bar.

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

Dynamic Table with repeating Subform

Avatar

Level 1

Hello,

I am maiking a form which has a Dynamic Table with a repeating Subform.  The repeating subform has a dropdown list field which has three options for the user to pic.  "LABOR", "EQUIPT.", & "MATL."

1.png

The way I want the form to work is the user will choose which item they want to add to the form with the dropdown list.  Whatever amount they put into the "Amount" column will go to the corresponding total "LABORTotal", "EQUIPTTotal", & "MATLTotal"

The repeating Subform is basically the Row1, but I have the table split up into subforms because of issues I had eariler with the form.  The repeating subform title is "detail". 

I cannot get the sums for the 3 items to go into the corresponding totals field.  This is the script that I have for the labor total field:

form1.total.LABORTotal::calculate - (JavaScript, client)

var nAmount = xfa.resolveNodes("detail[*].Table1.Row1.AMOUNT");

var nItem = xfa.resolveNodes("detail[*].Table1.Row1.ITEM");

var nSum = 0;

for (var i=0; i<nAmount.length; i++)

{

    if (nItem.item[i].rawValue == "LABOR")

    {

    nSum = nSum + nAmount.item(i).rawValue;

    }

}

This.rawValue = nSum;

I am not familiar with loop scripting or var scripting so I know I am getting it wrong somewhere. 

I would greatly appreciate any help!

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

Okay,

Here is your form back to you: https://acrobat.com/#d=IA67zcTBrWlnpcYS234*XQ.

The issue wasn't the script. If you select the dropdown and go to the Object > Binding palette, you will see you had ticked "Specify values" and these were set to 1, 2 and 3.

This meant that if the user selected LABOR, the value of the dropdown was "1" and NOT "LABOR". This was throwing the if statement.

I deselected the specify values and it worked as expected.

Hope that helps,

Niall

View solution in original post

8 Replies

Avatar

Level 10

Hi,

do you get any errors in the JavaScript Console when you test the form in Acrobat?

I think the there is one of because of this line:

if (nItem.item[i].rawValue == "LABOR")

which should be:

if (nItem.item(i).rawValue == "LABOR")

Avatar

Level 1

Oops I dont know how that ended up being different when I put it on here but they are the same in my form (like how you put it with the item(i) instead of the brackets)

And the weird thing is, I do not get any errors at all when previewing the form, or checking script syntax.  I notice that I do get this error using the java console in the preview:

ReferenceError: This is not defined

12:XFA:form1[0]:total[0]:LABORTotal[0]:calculate

Not sure what it means though, any ideas?

Thanks!

Avatar

Level 10

Hi,

It might be a pasting issue into the forum, but "This", should be "this".

Hope that helps,

Niall


PS: this is on line 12 of the script.

Avatar

Level 10

Hi,

if possible for you, share your form with us.

It will make it easier for us to find the bugs.

You can use Acrobat.com to upload your form.

Avatar

Level 1

Sorry guys, havent been able to upload the form until now because of some computer issues.  Got them squared away now.

Here is the form:

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

Not 100% how my form is because I took out some of our companies information and whatnot, but the fields/scripts in question are all there.

Thanks agian for your help

Avatar

Level 1

Ahhhh you know what I didnt catch that.  But after correcting that it did not correct the issue "/ 

Avatar

Correct answer by
Level 10

Okay,

Here is your form back to you: https://acrobat.com/#d=IA67zcTBrWlnpcYS234*XQ.

The issue wasn't the script. If you select the dropdown and go to the Object > Binding palette, you will see you had ticked "Specify values" and these were set to 1, 2 and 3.

This meant that if the user selected LABOR, the value of the dropdown was "1" and NOT "LABOR". This was throwing the if statement.

I deselected the specify values and it worked as expected.

Hope that helps,

Niall

Avatar

Level 1

Niall,

Wow I know I clicked that when I was trying another route, but I forgot to unclick it.  Cant belive it was that simple.  Thanks for your help!

Considered solved!

Thanks again!