Wednesday 28 February 2018

Read text files that have line feed (LF) using X++

Here is an intrusting scenario, There was a task to read a csv file and do some xyz task. As we all developers know, it will work fine in Dev and when it comes to UAT, the actual scenario will come out.
The issue was, the file which they provided is with only Line Feed (LF) and hence it looks like below when opened in notepad.

we can see the line feed in the Notepad ++  as below.
As usual, the code did not work.  To fix this issue, I have added the below code

inputFile = new TextIo(@"c:\temp\Input.csv", 'R');
inputFile .inFieldDelimiter(',');
inputFile .inRecordDelimiter("\n");

which done the trick.

Note: If you have both line feed (LF) and carriage return (CR)
we can use inputFile .inRecordDelimiter("\r \n");



Removing Line Feed and Carriage Return from Strings

costCenter = strReplace(conPeek(_lineContainer, 17), '\n','');
 costCenter = strReplace(costCenter, '\r','');

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 "";
    }

}

Sunday 18 February 2018

How to change the product name of the Released Product in AX 2012

There might be scenarios, where you need to change the name or description of an item.
Microsoft Dynamics Ax provides a standard way to do this.
Here is it how to do.
1. Go to
Product information management --> Release products
2. Click on Language (Translation).
3.Select your language
4. and you can change product name and description.

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...