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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Sum in AX Dynamics 2012 R3

(0) ShareShare
ReportReport
Posted on by

Hi all, 

How to add real type fields. What syntax?Field ABS_sumAmountMST

I have the same question (0)
  • nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Sum in AX Dynamics 2012 R3

    Finally, could you please use only relevant tags in your questions. Now you used tags like "Connector for CRM", "Windows 8 and Mobile Apps", "Forecaster and FRx", "Reporting and BI" and others, even if they are not related. In general this doesn't serve your purpose. But instead I encourage you to put effort in describing your problem already in your initial question. That way it's more likely that others can help you.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Sum in AX Dynamics 2012 R3

    I think I already instructed you on that just a couple of messages above.

    If you are now in markChanged method, you can use this code:

    ABS_SumAmountMST.realValue(this.calculateSumAmountTransactCurrency());

    In general you can pass values by using "=" operator. For example if you want to pass number 5 to variable myNumber, you call myNumber = 5; It works just like in most other programming languages.

    If you want to pass the return value of this.calculateSumAmountTransactCurrency() into the ABS_SumAmountMST.realValue() method, you use the solution that I provided above.

  • Community Member Profile Picture
    on at
    RE: Sum in AX Dynamics 2012 R3

    How to pass returned sumValue for other method markChange and reset value. public void markChanged()

    {

       super();

       this.calculateSumAmountTransactCurrency();

       ABS_SumAmountMST.realValue();

    }

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Sum in AX Dynamics 2012 R3

    You should not call markChanged method, it's called automatically when the user selects record(s) in the form.

    But you should call your calculateSumAmountMST from markChanged method (if you wish to run your method every time the mark is changed).

    "How to call other method" works always the same way. "objectName.methodName()".

    Since markChanged and calculateSumAmountMST are in the same object (the form data source), you can call it with "this.calculateSumAmountMST()".

  • Community Member Profile Picture
    on at
    RE: Sum in AX Dynamics 2012 R3

    How to call other method in my published method. It called markChange which is overridden. Both methods are in data source custtrans datasource methods. One method is mark changed other is calculateSumAmountMST. How to call markchanged method in method calculateSumAmountMST

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Sum in AX Dynamics 2012 R3

    Your method doesn't need to return anything.

    Or, if you want to, you can call MyField.realValue(element.calculateSumAmountTransactCurrency()); This code should not be inside your method (that would be an infinite loop), it should be where you trigger the sum calculation.

    You know now how to calculate the sum, and how to set value to an unbounded field. How exactly you organize your code is up to you.

  • Community Member Profile Picture
    on at
    RE: Sum in AX Dynamics 2012 R3

    MyField.realValue(mySumValue) before return?

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Sum in AX Dynamics 2012 R3

    I already told you that in my first reply:

    If your field is called MyField (and AutoDeclaration is Yes), you can set value to it like this:

    MyField.realValue(mySumValue);

    What do you mean by "field menu item"?

    By the way, your code misses the amount of the first custTrans. In your while statement you should call getNext only after handling the sum of the current custTrans (that you had when you first entered the while statement.

  • Community Member Profile Picture
    on at
    RE: Sum in AX Dynamics 2012 R3

    How to set output setValue data to ABS_SumAmountMST  field menu item. Given my code:

    public real calculateSumAmountTransactCurrency()

    {

        CustTrans custrans;

        real sumValue;

        MultiSelectionHelper helper = MultiSelectionHelper::construct();

    ABS_SumAmountMST.realValue(0);

       //super();

       //sumAmountMST.realValue(0);

       helper.parmDatasource(CustTrans_DS);

       custrans = helper.getFirst();

       while (custrans.RecId != 0)

       {

           //info(custrans.AmountMST.toString());

           info(custrans.RetailStoreId);

           custrans = helper.getNext();

      //  ABS_SumAmountMST=sum(ABS_SumAmountMST, custrans.AmountMST);

          sumValue+=custrans.AmountMST;

       }

     //  return ABS_SumAmountMST;

      return sumValue;

    }

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Sum in AX Dynamics 2012 R3

    Just use the same data type than the field that you are summing!

    If you add multiple AmountMST values, it's still AmountMST. There's no special data type for "summed value", it's a number just like the amounts that you summed together.

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

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,339

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 824 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 600 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans