Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Unanswered

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

Posted on by Microsoft Employee
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
    ergun sahin 8,812 Super User 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
    Martin Dráb 225,490 Super User 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.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans