Tuesday 20 February 2018

Create Sales order through code with Dimensions X++ AX2012


Here we are going to see, how the sales order is created using the code. In the below code, I'm storing the data into a temp table and reading it to create a sales order.

 private SalesId createSalesOrder(MK_tempFileData        _tempData)
{

    AxSalesTable                    axsalesTable;
    SalesFormLetter                 salesFormLetter;   
    SalesTable                          lsalesTable;
    CustTable                           custTable;
    DimensionAttributeValueSetStorage   storage;
    DimensionAttribute                  attribute;
    DimensionAttributeValue             value;
    DefaultDimension                    defaultDimension;

    try
    {

        //Create Sales order
        custTable = CustTable::find(_tempData.CustNumber);
        lsalesTable.initFromCustTable();

        axsalesTable = AxSalesTable::newSalesTable(lsalesTable);
        axsalesTable.parmCustAccount(_tempData.CustNumber);
        axsalesTable.parmSalesType(SalesType::Sales);
        axsalesTable.parmDocumentStatus(DocumentStatus::Confirmation);
        axsalesTable.parmSalesStatus(SalesStatus::Backorder);
        axsalesTable.parmCustomerRef(_tempData.ClaimNum);
        axsalesTable.parmCommissionGroup(_tempData.CommissSalesGroup);
        axsalesTable.parmSalesGroup(_tempData.CommissSalesGroup);
        axsalesTable.parmSalesOriginId(_tmpSalesheaders.SalesOriginId);
        axsalesTable.parmSalesPoolId(_tmpSalesheaders.SalesPoolId);
        axsalesTable.parmPurchOrderFormNum(_tmpSalesheaders.PurchOrderFormNum);
        //Dimension
        storage = new DimensionAttributeValueSetStorage();
        attribute = DimensionAttribute::findByName("Department");
        value = DimensionAttributeValue::findByDimensionAttributeAndValue(
                                    attribute, _tempData.CompanyCode, false, true);
        storage.addItem(value);
       
        attribute = DimensionAttribute::findByName("Center");
        value = DimensionAttributeValue::findByDimensionAttributeAndValue(
                                    attribute, _tempData.CostCenter, false, true);
        storage.addItem(value);

        defaultDimension = storage.save();
        axsalesTable.parmDefaultDimension(gDefaultDimension);

        axsalesTable.doSave();
        numSOs++;
       
        //SO confirmation
       
        lsalesTable = axSalesTable.salesTable(lsalesTable);
        salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
        salesFormLetter.update(lsalesTable);
       
        return lsalesTable.SalesId;
    }
    catch (Exception::Error)
    {
        info(strfmt('@MKS52', _tempData.CustAccount));
        return "";
    }

}

No comments:

Update NuGet package to new MS D365FO version

1. Import the NuGet package files from LCS for that particular version please take the PU version files only. a. Goto LCS-->Asset Libra...