web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Business Central forum

Q: how to set up table relationship & calculate sum?

(0) ShareShare
ReportReport
Posted on by 75

Hi guys, i am new to BC development and just ran into a question.

Right now i am building a contract table for generating contract between vendors & customers, with primary key as "Contract No." Within the document page there is a item line part, which is another table with primary key as "Contract No. " and "Line No.". There is another FlowField in the Contract table which calculates the total of the item unit price in the item line.  

What i want to do is each time when i enter a new contract number, the new contract number goes into the Item Line Table, becoming a primary key, and when i select the item on the item line, the flowfield will show the total prices of this specific contract.

Please let me know if you have any ideas. Thank you so much.

My current status:

I add the OnInsert trigger under the contract table to insert the Contract No filed to the Item Line Table Field, and have a FlowField that sums the Item Line Table based on the Contract No. But this doesn't work.

Categories:
I have the same question (0)
  • Bigbigapple Profile Picture
    75 on at

    Hi Suresh, thanks for replying! The Contract No and Total Line Amount are populated correctly. But the flowfiled in the Contract Header Table is always 0.

  • Suggested answer
    Suresh Kulla Profile Picture
    50,251 Super User 2025 Season 2 on at

    Check if the Contract Item table has values populate correctly in the Contract No. and Total Line Amount. Are you getting an error? or the calculation is showing the wrong amount.

  • Bigbigapple Profile Picture
    75 on at

    Thanks Stefano! Your answer helps a lot. I used the auto increment in the line No field and it works fine now. But for some reason, the flowfield, which is in the Header Table and is used to calculate the entire amount of one contract, is not working. I've set the the Total Line Amount field in the List Table as SumIndex Field, and my formula should be correct. Can you give me some ideas of how to make it work? Thanks a lot!

    formula: 

    CalcFormula = Sum ("Contract Item"."Total Line Amount" WHERE (ContractNo = field (ContractNo)));
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    I've not so clear your scenario, but if you're in a situation of a Header table and a Line table, if your LIne table has a proper table relation with the Header, the key fields are automatically populated when you insert a new Line record.

    The Line table should have two key fields like Contract No and Line No. TableRelation property must be set like Line."Contract No" = Header."Contract No". In the OnInsert trigger of the Line table you've only to calculate the Line No. value for the newly inserted line.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans