Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Create a secondary calculation in a repeating subform based on a drop-down list?

Avatar

Level 3

Hi all,

I need a crazy bit of scripting. Not sure it's even possible.

          What I have:

  1. repeating subform SummarySub with dollar amount
    1. calculation field at end of form TotalOver gives total dollar amount from all iterations of SummarySub

      so far, so simple. but then:
  2. I need another, repeating subform SubRow at the end of the form to give another total:
    1. based on Payer Name drop-down list in SummarySub
    2. and break out totals from all iterations of SummarySub based on payer names as chosen by the user.

Ideally, the subform (B) (Payer Totals) at the end of the form would add instances as the user exits the Payer Name field. I haven't been able to figure out how to do that and keep the value in the (Payer Name) field of the added instance.

Does any of this make sense?

I'll appreciate any help.  I'm trying to learn more about JavaScript in LC, but my deadlines just keep coming....

Many thanks

Laura

Dropbox - AFBS_OverpaymentReport_121914.pdf

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Laura,

Have a look at this modified version of your form, https://sites.google.com/site/livecycledesignercookbooks/home/AFBS_OverpaymentReport_010115.pdf?attr....  I have added a subform called PayerTotals, which has a per insurance company summary created in its calculate event.  The code looks like;


var oFields = xfa.resolveNodes("SummarySub[*]");



var nNodesLength = _SummarySub.count;



var nSum = 0;



var insuranceCompanies = {}



for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {



var item = oFields.item(nNodeCount);



if (!item.InsuranceCompany.isNull && !item.OverpaymentAmount.isNull) {



if (insuranceCompanies[item.InsuranceCompany.rawValue]) {



insuranceCompanies[item.InsuranceCompany.rawValue] += item.OverpaymentAmount.rawValue


 


else {



insuranceCompanies[item.InsuranceCompany.rawValue] = item.OverpaymentAmount.rawValue


 


  nSum += item.OverpaymentAmount.rawValue;


 


totalover.rawValue = nSum;



_PayerTotal.setInstances(0);



for (var insuranceCompany in insuranceCompanies) {



var payerTotal = _PayerTotal.addInstance();



payerTotal.InsuranceCompany.rawValue = insuranceCompany;



payerTotal.totalover.rawValue = insuranceCompanies[insuranceCompany];



Hope this helps

Bruce

View solution in original post

5 Replies

Avatar

Correct answer by
Level 10

Hi Laura,

Have a look at this modified version of your form, https://sites.google.com/site/livecycledesignercookbooks/home/AFBS_OverpaymentReport_010115.pdf?attr....  I have added a subform called PayerTotals, which has a per insurance company summary created in its calculate event.  The code looks like;


var oFields = xfa.resolveNodes("SummarySub[*]");



var nNodesLength = _SummarySub.count;



var nSum = 0;



var insuranceCompanies = {}



for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {



var item = oFields.item(nNodeCount);



if (!item.InsuranceCompany.isNull && !item.OverpaymentAmount.isNull) {



if (insuranceCompanies[item.InsuranceCompany.rawValue]) {



insuranceCompanies[item.InsuranceCompany.rawValue] += item.OverpaymentAmount.rawValue


 


else {



insuranceCompanies[item.InsuranceCompany.rawValue] = item.OverpaymentAmount.rawValue


 


  nSum += item.OverpaymentAmount.rawValue;


 


totalover.rawValue = nSum;



_PayerTotal.setInstances(0);



for (var insuranceCompany in insuranceCompanies) {



var payerTotal = _PayerTotal.addInstance();



payerTotal.InsuranceCompany.rawValue = insuranceCompany;



payerTotal.totalover.rawValue = insuranceCompanies[insuranceCompany];



Hope this helps

Bruce

Avatar

Level 3

Hi Bruce,

Thank you so much for your response!!  I'm sorry I didn't see it for so long, I think my forums aren't forwarding to my email anymore.

I'm going to test this out and study your script, too.

Again, I can't thank you enough. I'm going to ask you one more question: can you recommend a resource for learning (for a total newbie) about JS for LiveCycle? I'm doing tutorials on Codecademy, but I'd like to read material specific to LC.  The Adobe manuals are over my head at this point...

Thank you,

Laura

Avatar

Level 10

Hi Laura,

The only thing specific to LiveCycle Designer that I know of is J.P Terry's book http://www.adobepress.com/store/adobe-livecycle-designer-second-edition-creating-dynamic-97801334915...

There's also some introduction to general JavaScript on MDN Learn JavaScript | MDN.  Adobe Reader uses the SpiderMonkey JavaScript engine which is also used by FireFox, though I think a fairly old one, maybe 1.7 or 1.8 so there are a lot of things on the MDN site that does not apply.

Good luck

Bruce

Avatar

Level 3

Hi Bruce,

thank you again for the wonderful script.  It works perfectly, and I've been able to use it in two other forms.

I've been studying the JP Terry book, and continuing with codecademy to try and learn more about javascript. I understand some of the concepts, but not yet able to apply them correctly.  I've also been going through your script line by line to try and learn what the different elements mean or do. I'm way over my head!

For this form, my boss wants the same script function, but needs to also affect the total with another set of factors, subtracting the "AmountRemitted" from the PayerTotal.  Worse, the subform containing "AmountRemitted" has to repeat, so there will be multiple amounts to subtract from the total.  Not sure if that makes any sense.

I think what I need is a "for" loop for the SubRowTwo subform that can look through each iteration of that subform. I barely understand how to write the syntax, but have no idea of the rest of it (yet).

Dropbox - AFBS_PTM_bruce script_TEST.pdf

As before, thank you for any help.  I don't know if it's ok to ask this, but do you or anyone you know do freelance consulting?

Many thanks

Laura

Avatar

Level 10

Hi Laura,

You are right with the need for the nested for loop, If add this code to the calculation event.

 

    var nTotalRemitted = 0;

 

    var oAmountsRemitted = item.resolveNodes("SubRowtwo[*]");

 

    var nRemittedLength = item._SubRowtwo.count;

 

    for (nRemittedCount = 0; nRemittedCount < nRemittedLength; nRemittedCount++)

 

    {

 

        var oRemittedItem = oAmountsRemitted.item(nRemittedCount);

 

        var nAmountRemitted = parseFloat(oRemittedItem.AmountRemitted.rawValue);

 

        if (!isNaN(nAmountRemitted))

 

        {

 

            nTotalRemitted += parseFloat(oRemittedItem.AmountRemitted.rawValue);

 

        }

 

      }

 

see the sample https://sites.google.com/site/livecycledesignercookbooks/home/AFBS_PTM_bruce%20script_TEST.pdf?attre...

There are some comments in the sample explaining some of the code

Regards

Bruce