Pages

Tuesday, November 1, 2016

Create sales order, sales line and confirmation from X++ code in AX7

I have installed few days ago Virtual Machine with AX7. I have described it on my blog post.
Today I would like to write some code which was often used in older versions of AX system. Let's try to create sales order and sales line from X++ and after all confirm it. At the end I will compare to what we have in 2012/2009.

First thing what you have to do is model. Create model.

Name it. In this case it is Development7.

Select existing package and Next.

You should finish with following.

As you may see AOT is diffrent to what we are used to in previous versions. In my opinion moving development to Visual Studio gets better for Dynamics. And now I would like name X++ rather to X# because as I see C# and X++ are getting closer from year to year which is fine because both have their pros and cons.

Let's add standad job. You can do this by pressing right click on project name and select Add and naxt New Item...


Select Job.

Right click on more time on project name and this time select Properties. As you may see on screen below, what I'm doing is selecting company on which I would like to have orders and lines created. In this case it is BRMF company.




Below code. Code is almost the same as I'm using on AX 2012. We may assume at this moment that code in AX7 is the same as in AX2012. We will see in future how it is, when I will investigate new AX7.

public static void main(Args _args)
{
    SalesTable       salesTable;
    SalesLine        salesLine;
    SalesFormLetter  salesFormLetter;
    InventDim        inventDim;
    NumberSeq        numberSeq;
    
    numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
    numberSeq.used();
    
    // Sales table
    salesTable.SalesId = numberSeq.num();
    
    salesTable.CustAccount = "BRMF-000002";
    
    salesTable.ShippingDateRequested = today();
    
    salesTable.SalesType = SalesType::Sales;
    
    salesTable.initFromCustTable();
    
    if (!salesTable.validateWrite())
    
        throw Exception::Error;
    
    salesTable.insert();
    
    
    // Sales lines
    salesLine.SalesId = salesTable.SalesId;
    
    salesLine.ItemId = "BRMF020";
    
    salesLine.SalesQty = 2;
    
    inventDim.InventSiteId = "SAL-01";
    
    salesLine.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;
    
    salesLine.createLine(true, true, true ,true ,true, true);
    
    
    // Confirmation
    salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
    
    salesFormLetter.update(salesTable);
    
    info(strFmt("Sales %1 created and confirmed.", salesTable.SalesId));
}


Right click on job and Set as Startup Object.


Run job by pressing F5. Sales order created.












Go to accounts receivables and all sales orders and find previously created. Select tab SELL. Find GENERATE group and click on Confirmation.



Sales order is confirmed.

Also we can see how line is looking,

It seems that a lot of code is reused from older AX versions in new AX7 which is fine for us. However as much as I'm reading I see there are a lot of new fantastic technologies which we will investigate in next posts.

3 comments:

  1. Hi,

    I am getting error
    An exception of type 'Microsoft.Dynamics.Ax.Xpp.ErrorException' occurred in Dynamics.AX.ApplicationSuite.Table.SalesLine.netmodule but was not handled in user code

    Additional information: Update has been canceled.

    It comes when salesLine.createLine(true, true, true ,true ,true, true);
    is triggered.


    Regards,
    Smit
    smitjpatel31@gmail.com

    ReplyDelete
    Replies
    1. check the mandatory fields of salesline and salestable

      Delete
  2. This comment has been removed by the author.

    ReplyDelete