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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to use math inside forms ?

(0) ShareShare
ReportReport
Posted on by 440

Hi i am new with dynamics AX. I am using AX 2009 , i have some trouble using simple math inside forms in AOT . 

What i want to do is simply get the values from my table(which has Field1 Field2 and Field3) and make the method calculate Field1+Field2 = Field3
and field3 is empty so it should uptade itself after the sum.

3823.ax2.PNG 

Alan1 Alan2 and Alan3 are my fields. And this is the code i tryed but it didnt worked out.

public boolean modified()
{
Alan3.value(Alan1.value()+Alan2.value());
update_recordset _deneme1

setting Alan3=_deneme1.Alan1+_deneme1.Alan2;

return _deneme1.Alan3;

}

( _deneme1 is my table) and this code is inside my forms design ;

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi,

    in general you have to possibilies. You could either write the sum while saving the record (in the tables update or insert method) or you can do it live using a so called display method. The display method can be created on the table or on the datasource in the form. (see msdn.microsoft.com/.../aa595058.aspx).

    Kind regards

    Andi

    PS: To make things easier i would create the display method on the table. Then create a field group on the table and but the two fields and the display method in there. On the form add the field group.

  • DogahanMetin Profile Picture
    440 on at

    after your suggestion i chanced to this :

    2 fields in field gruops and display method inside table . and changed the code like this : 

    display int64 modified()
    {
    Alan3.value(Alan1.value()+Alan2.value());
    update_recordset _deneme1


    setting _deneme1.Alan3= _deneme1.Alan2 + _deneme1.Alan1;

    return _deneme1.Alan3;

    }

    still not working.. i think my code is wrong. but i cant find whats wrong with it. Can you help me with my code ?

  • Community Member Profile Picture
    on at

    Hi, you're mixing things up. If you use the display method approach try it this way:

    display int summedAlan()

    {

     return this.Alan2 + this.Alan1;

    }

    Now drag the summedAlan method to the field group

  • Verified answer
    Community Member Profile Picture
    on at

    By the way: if your want to use the other approach (with your field alan3), then create overwrite methods insert and update on the table and fill in this code

    void insert() // or update

    {

      this.Alan3 = this.Alan1 + this.Alan2;

    }

    In this case you don't need the display method and you can add the field Alan3 to your group. I prefer this technique most of the times as the calculation is only done on inserts and updates. If you use the display method approach the display method is called whenever you open the form (and this x-times). You may add a breakpoint in your display method to see that.

  • DogahanMetin Profile Picture
    440 on at

    Thanks alot for helping me. Your last suggestion work out perfectly for me. only problem is when i try to calculate the Sum Field3 , it only shows the sum only when i press Save button. but thats not a big problem.

    I am trying to do some simple project for my university.

    @ANDIRUDI i have few more questions about form creations and design. They are not diffucult i think. Can you give me your email adress so i can contact you if you have some free time to help me out ?

    Thanks in advance!

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans