TechNinjutsu‎ > ‎

Create return order in Dynamics AX 2012 using AIF with ReturnReturnOrderInService

posted Jul 17, 2014, 2:11 PM by d graham   [ updated Jul 17, 2014, 2:14 PM ]
I couldn't find any examples of this on the net, so here is an example of how to use AIF to create a return order in Dynamics AX 2012.

Note: this is sample code only and should probably not be used in production, is without any warranty, and may be missing fields etc

public static AifEntityKeyList createReturnOrder(SalesTable _salesTable)
{
    SalesLine                           salesLine;
    AifEntityKeyList                    AifEntityKeyList;
    AxdReturnOrderIn                    AxdReturnOrderIn;
    ReturnReturnOrderInService          rrois = ReturnReturnOrderInService::construct();
    ReturnReturnOrderIn                 ret = new ReturnReturnOrderIn();
    AfStronglyTypedDataContainerList    salesTableList, salesLineList, inventDimList;
    ReturnReturnOrderIn_SalesTable      rroiSalesTable;
    ReturnReturnOrderIn_SalesLine       ReturnReturnOrderIn_SalesLine;
    ReturnReturnOrderIn_InventDim       ReturnReturnOrderIn_InventDim;
   
    AxdReturnOrderIn = ret.getAxdInstance();
    salesTableList = ret.createSalesTable();
    rroiSalesTable = salesTableList.addNew();
    rroiSalesTable.parmCustAccount(_salesTable.CustAccount);
    salesLineList = rroiSalesTable.createSalesLine();
 
    while select salesLine
        where salesLine.SalesId == _salesTable.SalesId
    {
        ReturnReturnOrderIn_SalesLine = salesLineList.addNew();
        ReturnReturnOrderIn_SalesLine.parmItemId(salesLine.ItemId);
        ReturnReturnOrderIn_SalesLine.parmExpectedRetQty(-abs(salesLine.SalesQty));
        ReturnReturnOrderIn_SalesLine.parmInventDimId(salesLine.InventDimId);
        ReturnReturnOrderIn_SalesLine.parmCustAccount(salesLine.CustAccount);
        ReturnReturnOrderIn_SalesLine.parmSalesPrice(salesLine.SalesPrice);
       
        inventDimList = ReturnReturnOrderIn_SalesLine.createInventDim();
        ReturnReturnOrderIn_InventDim = inventDimList.addNew();
        ReturnReturnOrderIn_InventDim.populateFromTable(InventDim::find(salesLine.InventDimId));
    }
   
    AifEntityKeyList = rrois.create(ret);
    return AifEntityKeyList;
}
Comments