I am trying to calculate the sum of the "Purchase Line Total Weight" from the Purchase Line table and display it in the Purchase Header using a FlowField. However, the FlowField only updates when I insert a new line or when I close and reopen the page.
What I want to achieve is for the Purchase Header field to update immediately whenever a new line is inserted, an existing line is modified, or a line is deleted in the Purchase Line.
Could someone help me understand why the FlowField isn't updating as expected and suggest the best approach to make sure the field in the Purchase Header updates in real-time?
Answers
- if you want to show total to user, you have to apply time based script (https://www.packtpub.com/application-development/mastering-microsoft-dynamics-365-business-central)
- if you need total for internal calculation, you can define header record and use a calcfields method.
Also, where exactly should I add the code? I believe the code should be added to the Purchase Order Subform (the page where the lines are updated), since that's where the Purchase Line data gets updated. Would you agree with that approach?
But do you have to display it on Purchase Invoice page? Why not display it with the rest of the document totals?
- Purchase lines page don't know anything about purchase header page
You have following approaches:
- Refresh purchase header page every x seconds to update total fields. You can do it by using javascript addin in header page.
- Purchase line page has a "card like" part with some totals. You can add your total field to this part.
Flowfield on the purchase header table will be updated no problem. You don’t have to do anything in addition. So if you want to use it on a report or anything you could.
But your issue is that you want to update it on the purchase invoice page (header page) real time, isnt it. You said you want it to be updated immediately in your post. My question was why do you want it? What is the reason? Is this a requirement from customer?
If this real time update is for user to see when they add/modifying/ deleting then easier will as suggested by me and lupost is to add it in the document totals (card like part on the subpage!