Refresh total amount

Explorer ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

Hi,

I have a big problem with a calculation on my form or lets say it works in a strange way.

Well, I guess it had to do with the order they are calculated.

There are two fields (date) and one field (number) which calculates the difference of the two date fields as days.

E.g.

Field 1: 2018.01.26

Field 2: 2018.01.28

Field 3: 2

Field 4: 70€

That works correctly and they are updated immediatly when I'll change the date values. So far so good.

Then I've created 5 more fields format is number.

Where I can put more values into it to create a SubTotal.

The Subtotal would look like this:

140€ (which is 2x 70€ for the example above)

The SubTotal is created like

Sum1+Sum2+Sum3+Sum4+Sum5

Then I've also a Checkbox (Discount Yes/No) default to No.

When checked I display another Field where you can put a value into which will be substracted from the SubTotal field.

Now the Problem for the SubTotal field in the calculation event I placed the following:

Sum1, Sum2, Sum3, Sum4, Sum5

This works for the very first time but when I'll late change one of the date fields SubTotal isn't calculated anymore. Now the strange thing if I'll click the Discount checkbox 2 times the value for SubTotal is calculated correctly (I know that sounds a bit confusing at all.)

So my question would be ignoring the fact of possible wrong order for the calculation of the fields is there a way lets say a refresh I could send to the whole form to get the correct calculation? Well, or in other words what event happens when I check / uncheck the Discount checkbox because then it works? So maybe I can do the same from code to refresh the form.

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

263

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Most Valuable Participant , Jan 26, 2018 Jan 26, 2018
Because each time you change the value of any field in the file it triggers the calculations of all fields, and the second time you do it the fields already have their correct values, so the result is correct.Why not change the calculation order? That's the best approach and it will not affect anything else in the file. Any other solution is problematic.

Likes

translate

Translate

Translate
Most Valuable Participant ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

Yes, you need to fix the fields calculation order. You can do it by clicking on Tools, Prepare Form and then click on "More" at the right side of the window and then on "Set Field Calculation Order".

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

So my guessing was right but that does not answer what happens when clicking the Discount checkbox 2 times.

Like I've mentioned that solves the issue but why and how? So still the question is can I do that refresh (the discount checkbox seems to make) from Javascript directly instead of changing the order?

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

Because each time you change the value of any field in the file it triggers the calculations of all fields, and the second time you do it the fields already have their correct values, so the result is correct.

Why not change the calculation order? That's the best approach and it will not affect anything else in the file. Any other solution is problematic.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

Well let's say I'm just curious how I could solve that with javascript. On the other hands because there are a lot of fields and changing the order of all would take awhile.

Would love to see this trigger in javascript if possible just for my reference?

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

Each field has a calcOrderIndex property. You can use a script to set the order of all the fields by setting this value.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

One can place a custom calculation in the field one wants calculated last that performs all the calculations and set the resulting field values in the order one wants the calculation performed and there is not issue with the order in which Acrobat adds fields to the calculation order.

It is also possible to highlight multiple field names in the Set Calculation Order window and move them up or down as a group.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

Ok I'll see I was hoping for something like this.refresh....... to refresh the whole form at once.

No problem I've changed the order now works as suggested.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

There is the Doc.calculateNow() method that forces calculation but that won't help if the calculation order is off. But honestly, the more calculated fields you have, the more it makes sense to remove the calculations from the fields themselves and consolidate all of the calculations into a single, hidden, field that updates everything... much easier to manage.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 29, 2018 Jan 29, 2018

Copy link to clipboard

Copied

Thanks a bunch! I'm really thankful.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

Yes that make sense to me.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines