Thursday, 29 December 2016

Create Sales order using X++ in AX2012 R3

Note: in the below code I am sending the parameter from .Net using WCF service 

private SalesId createAXSO(AMSSalesOrderContract _SOContract)
{

   SalesTable salesTable;
SalesLine salesLine;

AxSalesTable axsalesTable;
AxSalesLine axSalesLine;
SalesFormLetter salesFormLetter;

;
    //Create Sales order
    custTable = CustTable::find( _SOContract.custAccount());
    salesTable.initFromCustTable();

    axsalesTable = AxSalesTable::newSalesTable(salesTable);
    axsalesTable.parmCustAccount( _SOContract.custAccount());
    axsalesTable.parmSalesType(SalesType::Sales);

    axsalesTable.parmDocumentStatus(DocumentStatus::Confirmation);

    axsalesTable.parmDeliveryDate(systemDateGet()+ 30);
    axsalesTable.parmSalesStatus(SalesStatus::Backorder);

    axsalesTable.doSave();
    while (literator.more())
    {
            lSalesLineContract = literator.value();
            salesLine.initFromSalesTable(salesTable);

            axSalesLine = AxSalesLine::newSalesLine(salesLine);
            axSalesLine.parmItemId(lSalesLineContract.itemId());
             //////Mandatory Values
            inventDim.InventSiteId = "AUS";
            inventDim.InventLocationId = "EPH";
            inventDim = InventDim::findOrCreate(inventDim);

            axSalesLine.parmInventDimId(inventDim.inventDimId);
            axSalesLine.parmCurrencyCode("AUD");
            axSalesLine.parmSalesQty(4);
            axSalesLine.parmSalesPrice(20.00);
            axSalesLine.doSave();
        literator.next();
    }

    //SO confirmation
    salesTable = axSalesTable.salesTable(salesTable);
    salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
    salesFormLetter.update(salesTable);
// SO invoicing
salesFormLetter = salesFormLetter::construct(DocumentStatus::Invoice);
salesFormLetter.update(salesTable);

    return salesTable.SalesId;
}

No comments:

Import and Export file from BLOB storage Account(Azure) in D365 F&O using X++

  Import and Export file from BLOB storage Account in D365 F&O using X++ Import: /// <summary> /// MKInventQualityOrderLineService...