Auto-refresh (SOLVED)

If you think that something doesn't work in Aware IM post your message here
Post Reply
jannes
Posts: 100
Joined: Tue Jul 02, 2019 12:22 pm

Auto-refresh (SOLVED)

Post by jannes »

Auto-refresh doesn't work as expected when deleting a record (in a child BO)

See the attached BSV :
1) Orderheader / OrderLines : it works OK
2) Parent / Child : deleting the child-record doesn't refresh the sum-total

What could be the difference why 2) isn't working ...

What I did :
- The parent has auto-refresh (on child) in the main-form
- Update-rule of the main is enabled and dynamic
- The query of the parent has auto-query for both (parent + child)

regards
Jannes
Attachments
jannesparenttotal2.zip
(48.79 KiB) Downloaded 282 times
Last edited by jannes on Sun Aug 22, 2021 6:25 pm, edited 4 times in total.
PointsWell
Posts: 1457
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: Auto-refresh

Post by PointsWell »

In your Parent BO your calculation rule does not have a trigger.

You need to have the rule run when a child is inserted into or removed from the child attribute.

Check out page 375 of the current User Guide for

Code: Select all

If Transaction WAS ADDED TO Account.Transactions Then INCREASE Account.Balance BY AddedTransaction.Amount
WAS ADDED TO would be the trigger to then do your SUM
jannes
Posts: 100
Joined: Tue Jul 02, 2019 12:22 pm

Re: Auto-refresh

Post by jannes »

Hi Pointswell,

Thnx replying.

It's all about deleting a child record.

The SUM is working but the updated amount is not updated in the MAIN-form (Parent) when DELETING a child: Not OK

The updated amount
- is updated correctly in the MAIN-form (Parent) when ADDING a child: OK
- is updated in the Parent Query : OK

Doing a manual refresh on the screen (main Parent) does show the updated amount (when adding or deleting).

Adding these business-rules on Parent don't help either.
If Child WAS ADDED TO Parent.oo_Child Then INCREASE Parent.Amount BY Parent.oo_Child.Amount
If Child WAS REMOVED FROM Parent.oo_Child Then REDUCE Parent.Amount BY Parent.oo_Child.Amount
The result is even worse : There is no update on adding or deleting.

Questions :
Why does the auto-refresh work as expected on orderheader / orderlines and not on parent /child ?
How to establish an automatic auto-refresh on parent when deleting a child-record ?

ps.
I uploaded a new bsv.
PointsWell
Posts: 1457
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: Auto-refresh

Post by PointsWell »

jannes wrote: Sun Aug 22, 2021 9:50 am Adding these business-rules on Parent don't help either.
If Child WAS ADDED TO Parent.oo_Child Then INCREASE Parent.Amount BY Parent.oo_Child.Amount
If Child WAS REMOVED FROM Parent.oo_Child Then REDUCE Parent.Amount BY Parent.oo_Child.Amount
The result is even worse : There is no update on adding or deleting.
Yeah, this won't work because you are not adding the new Child.Amount you are adding Paren.oo_Child.Amount

Logically you want to add only the new AddedItem to the Parent.Amount Added being a reserved prefix (similarly Removed for deleted BOs)

Code: Select all

If Child WAS ADDED TO Parent.oo_Child Then INCREASE Parent.Amount BY AddedChild.Amount
Alternatively completely re sum the child BOs
jannes
Posts: 100
Joined: Tue Jul 02, 2019 12:22 pm

Re: Auto-refresh

Post by jannes »

Thnx, I now use :

If Child WAS ADDED TO Parent.oo_Child Then INCREASE Parent.Amount BY AddedChild.Amount
If Child WAS REMOVED FROM Parent.oo_Child Then REDUCE Parent.Amount BY RemovedChild.Amount


instead of

Parent.Amount=SUM Child.Amount WHERE (Child IN Parent.oo_Child)


but the amount is still not refreshed in the form.
It is only refreshed in the grid of the query.
jannes
Posts: 100
Joined: Tue Jul 02, 2019 12:22 pm

Re: Auto-refresh (SOLVED)

Post by jannes »

A way to get it working :

Export the BSV as a XML, change the XML

1) Set the operand to "false"

<operation name="Del" type="delete_object" operand="false" css_class="" display_text="false">

2) Add in the business-rule: use_in_on_change="true"

<rule name="Rule1" use_in_on_change="true">
<rule_text>
Parent.Amount=SUM Child.Amount WHERE (Child IN Parent.oo_Child)
</rule_text>
</rule>


and import the XML again

@ Support
Can this be set somewhere so we don't have to change the XML ?
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Auto-refresh (SOLVED)

Post by Jaymer »

From the parent form, inside the child grid you are doing a “delete from list”, right?

Change it to run a process, which deletes the passed in child record.
Then make the parent refresh based on that process.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
PointsWell
Posts: 1457
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: Auto-refresh (SOLVED)

Post by PointsWell »

There are errors in some of the formulae

Code: Select all

Parent.Bedrag=SUM Child.Bedrag WHERE (Child IN Child.ob_Pers)
This won't work because you are saying do the calculation of all of the Child records that are in Child.ob_Pers

There are also issue in the order in which some of the BOs are being created.

Some are creating a new BO then creating a child BO before the first BO is saved, others (such as OrderHeader) create a BO save that BO and then add Child records which may be the cause of some of the inconsistency.
Post Reply