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

Challenging – Changing Total fields based on dropdown choices

Avatar

Level 1

I’m hoping I can get some help on a hurdle which I’m having a battle with.

In the attached form, I have 2 parts.

In part 1 the user is expected to enter amounts and identify where is those amounts currently sit: (Chequing, Savings, RSP – chosen by the “Account” column dropdowns)

In part 2, I’m looking to display the total Amounts but based on which account the user has chosen.

So if the user

  • chose “Chequing” for Row 1 and entered $10.00 for the Amount
  • chose “Saving” for Row 2 and entered $20.00 for the Amount
  • chose “RSP” for Row 3 and entered $500.00 for the Amount
  • chose “Savings” for Row 4 and entered $10.00 for the Amount

. . . Part 2 would look like

  • Total Amountin Chequing = $10.00

  • Total Amountin Saving = $30.00

  • Total Amountin RSP = $500.00

. . . but if the user changed the dropdown in Row 1 to RSP then Part 2 would look like:

  • Total Amountin Chequing = $0.00

  • Total Amountin Saving = $30.00

  • Total Amountin RSP = $510.00

I’ve been struggling with the use of variable, as I feel the solution lies with them, however I’m having a frustrating time. That, in addition to being a little unsure where best to place the code.

Any help with this would be greatly appreciated.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Sorry about that seems the first line of my code got 'lost', have updated you sample and uploaded to https://sites.google.com/site/livecycledesignercookbooks/home/westrat-Example1.pdf?attredirects=0&d=...

The missing line was

var total = 0;

Regards

Bruce

View solution in original post

4 Replies

Avatar

Level 10

Hi

You could use something like this JavaScript code in the calculate event of ChequingTotal.

var rows = Part1.resolveNodes("#subform[*]")

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

    var row = rows.item(i);

    var accountType = row.resolveNode("AccountType");

    if (accountType !== null && accountType.rawValue == "0") {

        var amount = row.resolveNode("AccountAmount");

        if (!amount.isNull) {

            total += amount.rawValue;

        }

    }

}

total;

Similar code in SavingsTotal and RSPTotal but with accountType.rawValue == "0" changed to accountType.rawValue == "1" and accountType.rawValue == "2" respectively.

You should make the binding values the same across all rows as Row4 had them as 3,4,5.  The code could be a lot easier if you used a table.  If could also be easier if you were only going to have 4 rows, but I have assumed you might add some more at some time.

Avatar

Level 1

First and foremost, I would like to thank you for your help. The time you put into responding to my issue is much appreciated.  I was hoping to impose at bit more. I’ve tried the code but did not find success. Any chance you could take another look? I attach the form with the coding included.

Again, thank you.

Avatar

Correct answer by
Level 10

Hi,

Sorry about that seems the first line of my code got 'lost', have updated you sample and uploaded to https://sites.google.com/site/livecycledesignercookbooks/home/westrat-Example1.pdf?attredirects=0&d=...

The missing line was

var total = 0;

Regards

Bruce

Avatar

Level 1

Fantastic! Bruce, thank you once again.