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

Beginner Problems - How to sum drop down lists in a table

Avatar

Level 1

Hi,

Please forgive my newness but I'm creating a table with 10+ rows and columns and need to sum the colums. The user is expected to select a number from a drop down list and I would like to sum those nbumbers up at the bottom of the column, seems simple enough...

I have named each cell in the bindings tab but can't seem to find the right sum script. I just started using livecycle and have had a good experience up until now.

I wish it was like excel where you just need to click or highlight the cells you want to sum and be done with it but I can't seem to find the easy button...

Cant you just highlight a column, name it and then use that name in a sum script?

Thanks so much for any help and I've looked around but can't get a grip on this one so I apologize if it's been asked before.

Go easy on me.

1 Accepted Solution

Avatar

Correct answer by
Level 3

You have to be very exact with referencing the fields, or the formulas will not work. If you renamed the fields from their default values, then you need reference them as you named them.

Here is an example of my hierarchy, named as you explained:

Capture.PNG

In this case, the scripting on the Total field will look like this:

this.rawValue = (Row1.A1.rawValue * 1) + (Row2.B1.rawValue * 1) + (Row3.C1.rawValue * 1) + (Row4.D1.rawValue * 1);

So that when I switch over to preview, it behaves properly:

Capture2.PNG

View solution in original post

8 Replies

Avatar

Level 3

There isn't really an "easy" way of doing this.

First, you will want to select your drop down box, go to the bindings window, and select "Specify Item Values" Make each of the values the value that you want to be added.

Next, in your total field at the bottom of the column, you will want to add a script on the calculate event. Make sure that Javascript has been selected and not formcalc.

Now, you will want to add something like:

this.rawValue = Row1.Cell2.rawValue + Row2.Cell2.rawValue + Row3.Cell2.rawValue;

Just make sure that your rows and cells are named properly, and add as many as you are planning to sum.

Hope this helps.

Avatar

Level 1

Thanks for your reply,

I was trying with FormCalc, when I tried javascript I get a zero in the total field but when I select number with the drop box (in preview) I don't get a total, just stays at zero.

Getting closer though...

Each drop down was named and given values 1 through 10, defaulot binding is set to normal (not sure if that makes a difference for my issue).

Seems like I'm overlooking something simple.

Thanks again.

Avatar

Level 3

Okay, I actually had to create a table and try this out.

The Total field needs to be  a numeric or decimal field, and when you click the patterns button, click both checkboxes to allow empty and allow zero.

Then, I had to multiply each of the values by 1, to force the field to look at them as a number, rather than a string. So, my code looked like this (again, using Javascript):

this.rawValue = (Row1.Cell2.rawValue * 1) + (Row2.Cell2.rawValue * 1) + (Row3.Cell2.rawValue * 1) + (Row4.Cell2.rawValue * 1);

Voila! It worked great once I did those two things.

Avatar

Level 1

Still not having any luck. I appreciate you simplifying it for me.

If I name the cells down the column A1, B1, C1, D1....etc my script should look like: (my drop downs start on row 4)

this.rawValue = (Row4.CellA1.rawValue * 1) + (Row4.CellB1.rawValue * 1) + (Row4.CellC1.rawValue * 1) + (Row4.CellD1.rawValue * 1);......etc

Or do I just have (Row4.A1.rawValue *1)......etc.

Thanks for the guidance.

Avatar

Correct answer by
Level 3

You have to be very exact with referencing the fields, or the formulas will not work. If you renamed the fields from their default values, then you need reference them as you named them.

Here is an example of my hierarchy, named as you explained:

Capture.PNG

In this case, the scripting on the Total field will look like this:

this.rawValue = (Row1.A1.rawValue * 1) + (Row2.B1.rawValue * 1) + (Row3.C1.rawValue * 1) + (Row4.D1.rawValue * 1);

So that when I switch over to preview, it behaves properly:

Capture2.PNG

Avatar

Level 1

Thank you so much, it's weird becase I thought I had that covered but obviously something was missing.

Truely appreciated.

Avatar

Level 1

One last thing.

I can manage this one on my own but it's taking so long to do it the way I'm going at it.

Basically, I've overpopulated most of my drop down list items, some by over 100 and I'd like to restrict the results that can be chosen by the user.

Right now, I'm deleting each value in the List Item field in the cell tab one by one but I have a lot more to go and this could take a few hours at this rate. Is there no way for me to just highlight a large chunk and remove it that way or do I have to go one by one clicking the delete button? I can't find any option to delete more than one at a time which seems odd.

Sorry if I'm not clear enough.

Thanks again either way.

~OK~

I just ended up copying a new cell to each overpopulated cell and rename. Seems to have worked and definitely saved some time, kind of obvious I suppose... but would be nice to be able to delete more than one item at once in the list item field.

Avatar

Level 3

Yeah, unfortunately, I only know of selecting each item in the drop down and deleting it individually as well. Which is... incredibly annoying. If you ever find out how to delete more than one at a time, let me know.