Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Adaptive Form Table - How to get field(s) to recalculate after removing a Row Instance

Avatar

Level 2

I have a simple table in a draft form - just trying to get the fields to recalculate after removing an instance of a row.

Adding an instance and using the field(s) work just fine - but if I remove a row - the TOTAL OF COLUMN does not recalculate.

I would prefer NOT to use an extra click to solve.  I am hoping I can recalculate upon 'removeInstance'.

How do I accomplish this?

Thanks

John

1 Accepted Solution

Avatar

Correct answer by
Level 2

All,

After working the problem through a little more - I solved it.  Here is how I did it.

  1. Set up the rule in the rule editor.
    1. I wanted the code to fire regardless of how many rows there were – so instead of having code in the ‘row total’ of each instance
      of the row – I added it to the ‘total of sums’ field.
    2. Since I want this code to fire all the time – I set the condition to fire when empty and when not empty.
    3. Then, I set the function result (sum) to add each of the instances of ‘row total’.

AEM Recalc 1.png

DO NOT Click ‘Done’  !!  If you do – you will need to rewrite half of what AEM deletes when you go back to edit.

This is how AEM wrote the code.

WHEN
Total of Sums is changed
AND
(Total of Sums is empty)
OR
(Total of Sums is not empty)
THEN
(Output of Function Sum)

As written by AEM, this code will never fire
because ‘total of sums’ is readOnly AND is waiting for its value to change.

2.  So then, while we are still in the rule editor screen, we switch from ‘Visual Editor’, to ‘Code Editor’

AEM Recalc 2.png

(and)
change the Event from ‘Value Commit’ (or whatever it is) and select ‘Calculate’.

AEM Recalc 3.png

Further Development

If you work through this example – you’ll notice that the calculation field displays “$0.00” when empty or “0”.  To fix that – I added this code the Rule
Editor – following much of the same steps above.

AEM Recalc 4.png
Instead of 'calculate' - I switched it to 'validate'.

if ( ( this.value == 0 || (this.value === null || this.value === "" ) ) )

{  
     this.value = null;

}

View solution in original post

12 Replies

Avatar

Level 10

I can only think of putting a refresh button on the form that would then calculate the new values and update them. If its event driven - i am not sure what would be a better event then a Refresh button.

Avatar

Level 8

Can you share the form?  Also what version of AEM are you using?

Avatar

Level 2

I am using 6.2.  Team will be updating to 6.3 soon.

How do I share a form?  The team has us on local hosts right now.

Thanks

Avatar

Level 10

If you tried using a Refresh button on the form - does that work?

Avatar

Level 2

I haven't tried for two reasons:

  1. I assume a button would work.
  2. I don't want the user to have to click refresh every time they remove a row.  We should be able to be intuitive enough to solve for that.  Essentially, #1 is in my back pocket - just in case.

Avatar

Level 10

Does the Object model offer an event that is fired when a row is removed. I have not trued that personally,

Avatar

Level 10

Here is older docs that list events. I assume most of them are still applicable.   Adobe LiveCycle ES3 * Events

Avatar

Level 2

I don't believe so.  Looked through that pretty extensively yesterday.  Will be looking again today.

Avatar

Level 2

Well... it seems to me that AEM Adaptive forms is regulating what you can and cannot do (versus LiveCycle).  This would be easy in Livecycle.

Avatar

Correct answer by
Level 2

All,

After working the problem through a little more - I solved it.  Here is how I did it.

  1. Set up the rule in the rule editor.
    1. I wanted the code to fire regardless of how many rows there were – so instead of having code in the ‘row total’ of each instance
      of the row – I added it to the ‘total of sums’ field.
    2. Since I want this code to fire all the time – I set the condition to fire when empty and when not empty.
    3. Then, I set the function result (sum) to add each of the instances of ‘row total’.

AEM Recalc 1.png

DO NOT Click ‘Done’  !!  If you do – you will need to rewrite half of what AEM deletes when you go back to edit.

This is how AEM wrote the code.

WHEN
Total of Sums is changed
AND
(Total of Sums is empty)
OR
(Total of Sums is not empty)
THEN
(Output of Function Sum)

As written by AEM, this code will never fire
because ‘total of sums’ is readOnly AND is waiting for its value to change.

2.  So then, while we are still in the rule editor screen, we switch from ‘Visual Editor’, to ‘Code Editor’

AEM Recalc 2.png

(and)
change the Event from ‘Value Commit’ (or whatever it is) and select ‘Calculate’.

AEM Recalc 3.png

Further Development

If you work through this example – you’ll notice that the calculation field displays “$0.00” when empty or “0”.  To fix that – I added this code the Rule
Editor – following much of the same steps above.

AEM Recalc 4.png
Instead of 'calculate' - I switched it to 'validate'.

if ( ( this.value == 0 || (this.value === null || this.value === "" ) ) )

{  
     this.value = null;

}

Avatar

Level 10

thanks for the detailed post. I am sure this will help a lot of ppl in the future.