Thursday, 29 December 2016

Code to cancel Sales order using SalesUpdateRemain class X++ AX 2012 R3

Note: In the below code, I am calling it from .Net using WCF parameter.

[SysEntryPointAttribute(true),
AifCollectionTypeAttribute('return', Types::String)]
public SalesId salesLineCancel(AMSSalesOrderContract _SOContract)
{
    boolean     ret;
    SalesId     lSalesID;
    SalesLine   lSalesLine;
    InventTrans     lInventTrans;
    str             errorStr;

    errorStr = this.validateInterfaceData(_SOContract);
    if ( errorStr!= "")
    {
        return errorStr;
    }
    try
    {
         /////////////////// CHANGE COMPANY/////////////////////
        changeCompany(_SOContract.company())
        {
            //Validate data
            errorStr = this.validateData(_SOContract);
            if (errorStr != "")
            {
                return errorStr;
            }

            ttsBegin;

            //Add your own logic to select and pass a specific sales line.
            lSalesLine.clear();
            if (literator != null)
            {
                lSalesLineContract = literator.value();
                /*select firstOnly forUpdate lSalesLine
                        where lSalesLine.PurchorderFormNum == lSalesLineContract.purchorderFormNum();*/
                select firstOnly forUpdate lSalesLine
                        where lSalesLine.SalesId == lSalesLineContract.salesId();
            }
            if(lSalesLine)
            {
                //lInventTrans    = InventTrans::findTransId(lSalesLine.InventTransId);
                if ( lSalesLine.SalesStatus != SalesStatus::Backorder)
                {
                   lSalesID = strFmt("@SYS4004577",lSalesLine.SalesId, lSalesLine.SalesStatus );
                    // ret         = SalesUpdateRemain::updateDeliveryRemainder(lSalesLine, 0, 0);
                }
                //Open order
                else
                {
                    //pass three parameters
                    //1.SalesLine buffer
                    //2.remainSalesPhysical, pass it as zero as you want to cancel full line
                    //3.remainInventPhysical, pass it as zero as you want to cancel full line
                    ret         = SalesUpdateRemain::updateDeliveryRemainder(lSalesLine, 0, 0);

                    if(ret)
                    {
                        lSalesID = strFmt("Sales Line # %1: of Sales id # %2 is Canceled",lSalesLine.LineNum, lSalesLine.SalesId);
                    }
                }

            }
            else
            {
                lSalesID = strFmt("Sales line not found/Invalid Line");
            }
            ttsCommit;
        }

    }
    catch
    {
        error("Sales line got exception while attempting to be cancelled.");
    }
    return lSalesID;
}

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

Wednesday, 28 December 2016

Cancel a specific Sales Line, using code (X++) AX2012

In AX2012, Using x++  a specific sales line can be cancelled, as by using the class "SalesUpdateRemain", in  below job we will see how to cancel a sales line using the class "SalesUpdateRemain" . 

static void mkCancelSalesLine(Args _args)
{
    boolean     ret;
    SalesLine   SalesLine;

   
    try
    {
        ttsBegin;       
       
        //Add your own logic to select and pass a specific sales line.
        SalesLine.clear();
        SalesLine   = SalesLine::findRecId(2137226141, true);   
        if(SalesLine)
        {
            //pass three parameters 
            //1.SalesLine buffer
            //2.remainSalesPhysical, pass it as zero as you want to cancel full line
            //3.remainInventPhysical, pass it as zero as you want to cancel full line
            ret         = SalesUpdateRemain::updateDeliveryRemainder(SalesLine, 0, 0);
   
            if(ret)
            {
                info(strFmt('Sales Line # %1: Canceled',SalesLine.LineNum));   
            }       
        }
        else
        {
            info('Sales line not found/Invalid Line');
        }
        ttsCommit;
    }
    catch
    {
        error("Sales line got exception while attempting to be cancelled.");
    }
}

Thursday, 22 December 2016

Walk through major features of Microsoft Dynamics AX 2012 Trace Parser (Part 1)

https://blogs.msdn.microsoft.com/axperf/2011/08/15/walk-through-major-features-of-microsoft-dynamics-ax-2012-trace-parser-part-1/


Cancel the sales order Dynamics AX X++

Cancel the Sales order 


Case1: Check the Line status is delivered or picked


private boolean identifyLineStatus(InventTrans  _inventTrans)
{
    boolean     ret;
    // identified as delivered by 
    if(_inventTrans.statusIssue == StatusIssue::Deducted)
    {
        //delivered
        ret =  false;
    }
    //identified as picked by checking the status on the InventTrans table
    if(_inventTrans.statusIssue == StatusIssue::Picked)
    {
        // picked
        ret = false;
    }
    
    return  ret;
}

Delete sales line with Line status as delivered

private void deleteDelivered(SalesID _salesID,lineNum _lineNum)
{
 
ttsbegin;
//update Sales Line
salesLine = SalesLine::find(_salesID, _lineNum, true);
 
salesLine.SalesDeliverNow   = -1;
salesLine.setInventDeliverNow();
salesLine.doUpdate();
 
//Post the delivery note
salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);
salesFormLetter.progressHide();                                // Hide the progress bar.
 
salesFormLetter.update(salesTable,                             // SalesTable
                       SystemDateGet(),                        // Delivery date
                       SalesUpdate::DeliverNow,                // Quantity to update (SpecQty)
                       AccountOrder::None,                     // AccountOrder
                       false,                                  // Proforma only?
                       false);                                 // Printout?
ttsCommit;

}

Delete sales line with Line status as picked

private void deleteDelivered(SalesID _salesID,lineNum _lineNum)
{
 
ttsBegin;
// Initialise classes
salesLine       = salesLine::find(_salesID, _lineNum, true);
inventMovement  = InventMovement::construct(salesLine);
inventTranspick = new InventTransWMS_Pick(inventMovement,tmpInventTransWMS);
 
// Create transaction record
TmpInventTransWMS.clear();
TmpInventTransWMS.initFromInventTrans(inventTrans::findTransId(salesLine.InventTransId));
TmpInventTransWMS.LineNum     = _LineNum;
TmpInventTransWMS.InventDimId = InventTrans::findTransId(salesLine.InventTransId).InventDimId;
TmpInventTransWMS.InventQty   = ( ABS( InventTrans::findTransId(salesLine.InventTransId).Qty ) * -1 );
TmpInventTransWMS.insert();
 
if( TmpInventTransWMS.InventQty != 0 )
{
    if( inventTranspick.validateTmp(TmpInventTransWMS) )
    {
        // Post the pick update
        InventTransWMS_Pick::updateInvent(inventTranspick,TmpInventTransWMS);
    }
}
 
//cancel order
salesLine.RemainSalesPhysical = 0;
salesLine.remainInventPhysical = 0;
salesLine.update();
ttsCommit;
}

Case2: Open sales order

//cancel order
ttsBegin;
salesLine.RemainSalesPhysical = 0;
salesLine.remainInventPhysical = 0;
salesLine.update();
ttsCommit;




for more information click on here.

Saturday, 10 December 2016

Code to create General Journal X++ (Dynamics AX 2012)

Code to create General Journal X++ (Dynamics AX 2012)

This post is mainly to guide you on how to use ledger dimension in AX 2012.


static void legerDimCreateGLJournal(Args _args)
{
    AxLedgerJournalTable journalTable;
    AxLedgerJournalTrans journalTrans;
    container            accCon;
    container            offSetCon;
    ;

    journalTable = new AxLedgerJournalTable();
    journalTrans = new AxLedgerJournalTrans();

    //Journal Name
    journalTable.parmJournalName("GenJrn");
    journalTable.save();

    journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
    journalTrans.parmTransDate(systemDateGet());
    journalTrans.parmAccountType(LedgerJournalACType::Ledger);

    //LedgerDimension  => Ledgeraccount, DAX 2009
    accCon = ["500200", "500200", 0]; 
    journalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(accCon));

    journalTrans.parmAmountCurDebit(2000);

    //OffsetLedgerDimension => OffsetLedgerAccount,  DAX 2009
    offSetCon = ["500300", "500300", 0];
    journalTrans.parmOffsetAccountType(LedgerJournalACType:: Ledger );
    journalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId( offSetCon));
  
    journalTrans.save();

    info(strFmt("Journal %1 created", journalTable.ledgerJournalTable().JournalNum));
}

How to post with Financial dimensions:

Format : 
["DisplayValue", "MainAccount", NumberOfDimensions, "DimensionName", "DimensionValue"]; 

E.g:
accCon = ["500200-Invent", "500200", 1, "Department", "Admin_1"]
AxdDimensionUtil::getLedgerAccountId(accCon)



Wednesday, 10 August 2016

Form Field allow edit based on conditons

some times we may get requirements to make only some fields to be to allow edit on the form grid control.
Here are the few steps, which make is easy

1. Create a Form method as below
///
/// This method is used to make fields editable based on conditions
///
///
/// 10/08/2016 by mallik
///

public void setFieldAccess()
{
   if(XXXX == YYY)
   {
       FrmDataSource_ds.object(fieldNum(FrmDataSource,LineNum)).allowEdit(false);
   
      FrmDataSource_ds.object(fieldNum(FrmDataSource,Field2)).allowEdit(false);
    }
}

2. Call the above method from the form Data source Active method after Super() as below

///
/// to check record edit
///
///
/// int
///
///
///  09/08/2016 by Mallik
///

public int active()
{
    int ret;

    ret = super();
    element. setFieldAccess();

    return ret;
}

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