Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

how to create run method in class and consume other data of same class in ax 2012 x++

(0) ShareShare
ReportReport
Posted on by
I'm developing a customization that needs to insert data in a form (ConsultSalesOrder), this data has to come from a class that contains the methods of all fields that will exist in this new form.
Here is one of the methods as an example:
pastedimage1625767350708v1.png
This method is getSalesLineMultPriceSalesQTY
which makes select in salesLine where is the quantity of item as you can see, then it multiplies with the item value (vendInvoiceTrans.PurchPrice) and who receives this value is the return (salesMultPriceQTY).
My question now is, how am I going to consume this method in my run and how am I going to insert this class that contains all these methods called (CalcIMCS) inside the init method that will have the function to call my class every time I click to open my form?
pastedimage1625767653793v2.png
 
  • ergun sahin Profile Picture
    8,816 Moderator on at
    RE: how to create run method in class and consume other data of same class in ax 2012 x++

    The question is not clear enough or I don't understand it.

    First, are there two classes or a form and a class?

    A second issue, is the second class completely independent from the first object?


    I'm not sure as I don't know your level but unless I misunderstood the question you're going to be asking pretty basic stuff. I'll give you information, pls guide me. So, we can reach the result quickly.

    Let's proceed step by step.

    Step 1: Instantiating a Class

    CalcIMCS    CalcIMCS = new CalcIMCS();

    Step 2: Parm Methods 

    Many classes/methods need initial values when used externally. For example, you used vendInvoiceTrans in the method you shared with us, but it is not clear where it came from.
    You are probably sending from the first class. Before using the second class methods you should pass all the values you need from the first class to the second class with the parm methods (or parm variables).

    CalcIMCS    calcIMCS = new CalcIMCS();
    VendInvoiceTrans vendInvoiceTrans = VendInvoiceTrans::find("related record");
    ;
    calcIMCS.parmVendInvoiceTrans(vendInvoiceTrans);
    calcIMCS.getSalesLineMultPriceSalesQTY();
    
    .
    .or
    .
    
    calcIMCS.getSalesLineMultPriceSalesQTY(vendInvoiceTrans);//Change getSalesLineMultPriceSalesQTY at the class

    Step 3: Get values

    CalcIMCS calcIMCS = new CalcIMCS();
    real                salesMultPriceQTY;
    VendInvoiceTrans    vendInvoiceTrans = VendInvoiceTrans::find("related record");
    ;
    calcIMCS.parmVendInvoiceTrans(vendInvoiceTrans);
    salesMultPriceQTY = calcIMCS.getSalesLineMultPriceSalesQTY();

    I don't get involved in the code(the process), but as Martin said, it didn't make much sense to me either.

  • Martin Dráb Profile Picture
    234,591 Most Valuable Professional on at
    RE: how to create run method in class and consume other data of same class in ax 2012 x++

    Your select statement looks wrong to me. There may be thousand order lines with the same ItemId and you'll get a random one, because your query doesn't specify which one should be returned. I don't know how you intend to link a vendor invoice line with a sales order line, but your current approach is definitely wrong.

    The usual source of data for forms are tables - open almost any form and you'll see that.

    If you want calculated values and therefore a persistent table isn't suitable, you can let your class populate a temporary table buffer. You'll use your temporary table as a form data source, bind controls to datasource fields in the usual way and then set the temporary buffer (populated by the class) to the data source in code.

    You can also use display methods defined on a table, on a form data source or a form itself.

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 565

#2
Martin Dráb Profile Picture

Martin Dráb 536 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 402 Super User 2025 Season 1

Product updates

Dynamics 365 release plans