Thursday, 22 December 2016

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.

No comments:

How to Disable “Advanced Filter or Sort” and Enforce Custom Filters on Any D365FO Form

 In Dynamics 365 Finance and Operations, users can apply filters through the “Advanced filter or sort” feature found under the Options tab...