Expand my Community achievements bar.

Addinstance TOTAL

Avatar

Former Community Member
I am making an estimate sheet with an add/ remove instance subform labeled "Instance". I can add and remove the forms with no problem. Within the instance is a numerical field called "Price". I need to SUM total the Price field on every instance that I add. Also, if I remove one of the instances, I need it to deduct from the total (I read there were errors with this).



These are the scripts I have in each field:



---------------------------------

-Instance-

_Instance.addInstance(1);



xfa.form.recalculate(1);



// Verify at least one instance of the numAmount field exists.

if (exists(detail[0].numAmount) == 1) then

Sum(detail[*].numAmount)

endif



-Total-

Sum(Instance.#Price[0][*].rawValue)

----------------------------------

I might be off by a few characters. I am a beginner with javascript/ livecycle, so I pretty much Frankensteined this code. Addinstance isn't something I can accomplish with Acrobat Pro alone. So I'm thrown into the fire w/ Livecycle.



I have searched in and out of google, this forum and livecycle help. I can't figure this problem out. Help will be extremely appreciated!
2 Replies

Avatar

Level 1
Drew,





It seems you're using Form Calc, and i think you should use JavaScript instead. You may have to do one of the following:





(a) code the "click" event in your add/delete instance button



(b) place your code in the "calculate" event for the sum field





You can use both FromCalc or JavaScript (i prefer JavaScript).





Refere to the "Purchase order" sample, use the "Dynamic interactive" variation. It has the same properties you want. The samples are on the LiveCycle Designer's installation directory.





Hope this helps.

Avatar

Level 3

Hi,

Please download the sample form from here.  https://acrobat.com/#d=Xxh9tEdKkYuByNDdKR4Geg

1. Place the below code  in the calculate event of your total field.

 

TotalField.rawValue = Sum(instance[*].price)

Make sure the script selected under language is formcalc.

Also to  Verify at least one instance of the numAmount field exists.

You can check the object panel of the subfom and under Binding TAb you can check the option "Repeat subform for each data item with Min count 1."

instance.png