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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Calculating total price based on dynamic fields

(0) ShareShare
ReportReport
Posted on by

I have created a custom form wherein I am adding fields dynamically on the initialisation of the form. The number of these fields is not set. I have to calculate the total price based on these field values. How do I go about it? Have tried using the display method but it did not work. Could you please push me in the right direction?

I have the same question (0)
  • Blue Wang Profile Picture
    Microsoft Employee on at

    HI ShravyaD,

    Have you tried to use computed column?

    Create a view and add code .

    An example: community.dynamics.com/.../computed-column-in-dynamics-ax-views

  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    Could you please explain what the fields have to do with total price? Otherwise it's not possible to say how the fields should be used for the calculation.

    Also, what exactly do you mean by fields? DialogField objects? Form control bound to datasource fields? Or something else?

    Assuming that you mean dialog field and assuming that your main problem is how to get values from these fields, store the objects (that you create during form initialization) in a collection, such as a Set object. When you want to get values, iterate the collection and call value() method on each object).

  • Community Member Profile Picture
    on at

    Hey Martin,

    these fields are records from the charges group table that is MarkupTrans. They are form controls and I am displaying them by iterating through my temp table that is similar to MarkupTrans. I have used a map to store the name and the value of the charge respectively.

  • Community Member Profile Picture
    on at

    This is the code that I used to add the controls dynamically:

    while (tempTable)

           {

               FormRealControl realControl;

               realControl = MainGroup.addControl(

                                               FormControlType::Real,

                                               tempTable.MarkupCode

                                               );

               realControl.label(strFmt("%1 (%2)",

                                       tempTable.MarkupCode,

                                       tempTable.MarkupCategory));

               realControl.dataSource(tempTable);

               next tempTable;

           }

  • Verified answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    Thank for the information. Can you now explain your problem, please? Note that if you don't know how to access the control, my previous suggestion is still applicable (you'll just store FormRealControl objects instead of DialogField objects).

    By the way, please use Insert > Insert Code (in the rich formatting view) to paste source code. It makes it easier to read and copy.

  • Community Member Profile Picture
    on at

    Hey Martin,

    I am able to access the controls and their values. The number of controls added depends on the number of records in the temp table. I also have a control with the label total price that I have to calculate based on these control values. I had written a display method for the same but when I do a test, the value in the total price control does not change.

  • nmaenpaa Profile Picture
    101,166 Moderator on at

    Could you share your code that calculates the total value? There is clearly something wrong with it, but our chances of figuring out the issue are very low if we can't see your code :)

  • Community Member Profile Picture
    on at

    display Price editFinalPrice()

           {

               real            chargesVal;

               Price           finalPrice;

               FormRealControl realControl;

               TempTable tempTbl = temptable::getAllRecordsFromTemptable();

               while (temptbl)

               {

                   finalPrice  = Price.realValue();

                   realControl = element.design().controlName(purCharges.MarkupCode);

                   if (tempTbl.MarkupCategory == MarkupCategory::Percent)

                   {

                       chargesVal  = realControl.realValue();

                       finalPrice  += chargesVal*0.01;

                   }

                   else if (tempTbl.MarkupCategory == MarkupCategory::Fixed)

                   {

                       chargesVal  += realControl.realValue();

                       finalPrice  = finalPrice + chargesVal;

                   }

                   next tempTbl;

               }

               return finalPrice;

           }

  • Suggested answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    Did you notice Martin's previous comment: "By the way, please use Insert > Insert Code (in the rich formatting view) to paste source code. It makes it easier to read and copy."

    Please format the code next time you share it so it's easier for us to read.

    Thanks!

    Also, I think you still didn't follow Martin's suggestion about storing the form controls in a collection class (such as a Set) when you add them to the form.

    Please do that. Then iterate that collection when you want to read the values from the controls.

  • Community Member Profile Picture
    on at

    I had not noticed it. Thanks. Yeah, will add a collection class.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 663

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 439 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 337 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans