Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

How to sum the amount in the table and pass it to a field for the total

Posted on by 1,295

Hi, 

I just need your help, I would like to know if how to pass the total amount to the field from one of the field in gridtable in form? can you help me on this? thank you

Ivan

Categories:
  • Suggested answer
    Code Work Profile Picture
    Code Work 15 on at
    RE: How to sum the amount in the table and pass it to a field for the total

    you can try this display method scenario is same

    community.dynamics.com/.../535285

  • SII1MNL Profile Picture
    SII1MNL 1,295 on at
    RE: How to sum the amount in the table and pass it to a field for the total

    Hi Nishant,

    Thank you for your response, yes its quite complicated what the client wants because it is not consistent at all. but I managed to set the field as editable since there is a field in the table for the computation. 

    Ivan

  • Verified answer
    Nishant2408 Profile Picture
    Nishant2408 705 on at
    RE: How to sum the amount in the table and pass it to a field for the total

    Hi Ivan,

    I have got our question now. As you explained, in total amount field data is coming from a display method which is not editable. But in your case it has to be editable, which seems a bit confusing requirement because total amount is sum of field #4 in sumOpportuinityTable, if user is going to edit it , there is no point in showing some of a particular field. Anyways based on your requirement in place of display method you can use edit() method which will make the field editable as well. Perform the same logic in edit method which will return your total amount.

    For more information go through the link.

    msdn.microsoft.com/.../aa637541.aspx

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to sum the amount in the table and pass it to a field for the total

    It will help to fetch all the row records of a table.

    Till it finds the records in table it will work.

  • Rati Sharabidze Profile Picture
    Rati Sharabidze 612 on at
    RE: How to sum the amount in the table and pass it to a field for the total

    Hi Ivan, you can create a display method in the datasource and put it in the grid. Remark: there will be no data field in the grid control. There will be Data method instead.

    Best regards

  • Mea_ Profile Picture
    Mea_ 60,274 on at
    RE: How to sum the amount in the table and pass it to a field for the total

    @Gautam Verma

    What is the purpose of  "where table1.RecId !=0"  ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to sum the amount in the table and pass it to a field for the total

    Try this it will help you!

    static void SumOfField(Args _args)

    {

    Table1 table1;

    ;

    select sum(Field1) from table1;   //Use "where" condition if required

    info(strfmt("%1",table1.Field1));

    }

    You can pass this value where ever you want to!

    *If you need to insert this value to gridtable of a form then you can write this code to init() method of that form and assign this value to desire field. So whenever the form is initialized you can see that value in your gridtable field.

  • SII1MNL Profile Picture
    SII1MNL 1,295 on at
    RE: How to sum the amount in the table and pass it to a field for the total

    Field #1 : smmOpportunityTable.TotalNetAmount()

    As-is : Sum of field #4

    To-be : Default data is sum of field #4, but user can edit it.

    the field #1 is in display method which you cannot simply edit it. I want to edit the total amount. I hope you get the situation. Thank you.

  • Nishant2408 Profile Picture
    Nishant2408 705 on at
    RE: How to sum the amount in the table and pass it to a field for the total

    Hi Ivan,

    you can write a simple query from the datasource table and fetch the sum of the amount field.

    let's say you have a table Table1 and amount field is there. Query will be like :

    Select sum(amount) from Table1 where {your condition};

    Table1.amount will give you the sum which you can pass as argument._

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

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

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,353 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,251 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans