Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

how can i ship the transfer order using x++ code

Posted on by 1,457
hi ,
everyone , i have created the transfer order using x++ code , and new transfer order are getting created in system but i need to ship the transfer order using x++ code can any one help me on this.
 
 
 
 
 
thanks,
Regards,
dinesh
  • Suggested answer
    Navneeth Nagrajan Profile Picture
    Navneeth Nagrajan 1,439 Super User 2024 Season 2 on at
    how can i ship the transfer order using x++ code
    Hi Dinesh,
     
    You can use this class called InventTransferParmLineCreate. This is the class that is called when you do a shipped or a received quantity. Also, when you need to ship a transfer order. There is a method called createShipLines. Based on this, you can modify your code for creating Transfer Journal Lines. 
     
    From your code it looks like you are trying to create Transfer order Shipment lines. A few points:
    1. For Exploded Transfer Order Lines:
        If you are trying to ship quantity of a product from the transfer order without exploding the transfer order lines then use the method called createShippedExplodedReceiveLines.
     
    2. For Non-Exploded Transfer Order Lines:
        If you are trying to ship quantity of a product from the transfer order without exploding the transfer order lines then use the method called createShipLineWithoutExplodeLines.
     
    You need to modify your code to fetch InventTransferParmLine and pass the InventDim value in there. Attached a piece of code that you need to add to your run() method from the createShipLines() method. Used the below mentioned code for a development in the past. 

           //variable declaration here.
            ttsbegin;
            InventTransferTable inventTransferTable = InventTransferTable::find(inventTransferParmTable.TransferId,true);
            if (! inventTransferTable.RecId)
            {
                throw error(strFmt(InventTransferTable::txtNotExist(),inventTransferParmTable.TransferId));
            }
            InventTransferParmLine  inventTransferParmLine;
            InventTransferLine      inventTransferLine;
            InventTrans             inventTrans;
            InventDim               inventDim;
            InventQty               qtyUpdate;
            LineNum                 lineNum;
            // <GEERU>
            InventTransferJourLine  inventTransferJourLine;
            // </GEERU>
            PdsCWInventQty          cwQtyUpdate;
            // <GEERU>
            if (!countryRegion_RU
                ||!((inventTransferParmTable.ShipUpdateQty == InventTransferShipUpdateQty::DocumentReturn_RU)
                    && inventTransferParmTable.ExplodeLines))
            {
                // </GEERU>
                Query query = this.buildCreateShipLinesQuery(inventTransferTable);
                QueryRun queryRun = new QueryRun(query);
                while (queryRun.next())
                {
                    inventTransferLine = queryRun.get(tableNum(InventTransferLine));
                    if (this.mustSkipInventTransferLine(inventTransferLine))
                    {
                        if (inventTransferParmTable.isShipmentCancellation())
                        {
                            throw error(strFmt("@SCM:TransferOrderCancellationWHSLoadLineExistsException"));
                        }
                        continue;
                    }
                    boolean isTransferOrderShipmentCancellation = inventTransferParmTable.CanceledShipmentJournalRecId != 0;
                    // <GEERU>
                    if (countryRegion_RU || isTransferOrderShipmentCancellation)
                    {
                        if (inventTransferParmTable.ShipUpdateQty == InventTransferShipUpdateQty::DocumentReturn_RU 
                            || isTransferOrderShipmentCancellation)
                        {
                            select firstonly inventTransferJourLine
                                    where
                                        inventTransferJourLine.TransferId == inventTransferLine.TransferId              &&
                                        inventTransferJourLine.VoucherId  == inventTransferParmTable.VoucherShipmentId &&
                                        inventTransferJourLine.LineNum    == inventTransferLine.LineNum;
                            if (!inventTransferJourLine.RecId)
                                    continue;
                        }
                        qtyUpdate = isTransferOrderShipmentCancellation ? 
                            inventTransferLine.calcCancelQty(inventTransferParmTable.ShipUpdateQty, inventTransferParmTable.VoucherShipmentId) :
                            inventTransferLine.calcShipQty(inventTransferParmTable.ShipUpdateQty, inventTransferParmTable.VoucherShipmentId);
                        if (PdsGlobal::pdsIsCWItem(inventTransferLine.ItemId))
                        {
                            cwQtyUpdate = isTransferOrderShipmentCancellation ?
                                inventTransferLine.pdsCWCalcCancelQty(inventTransferParmTable.ShipUpdateQty, inventTransferParmTable.VoucherShipmentId) :
                                inventTransferLine.pdsCWCalcShipQty(inventTransferParmTable.ShipUpdateQty, inventTransferParmTable.VoucherShipmentId);
                        }
                        else
                        {
                            cwQtyUpdate = 0;
                        }                    
                    }
                    else
                    {
                        // </GEERU>
                        qtyUpdate = inventTransferLine.calcShipQty(inventTransferParmTable.ShipUpdateQty);
                        if (PdsGlobal::pdsIsCWItem(inventTransferLine.ItemId))
                        {
                            cwQtyUpdate = inventTransferLine.pdsCWCalcShipQty(inventTransferParmTable.ShipUpdateQty);
                        }
                        else
                        {
                            cwQtyUpdate = 0;
                        }
                        // <GEERU>
                    }
                    // </GEERU>
                    // <GEERU>
                    if (((countryRegion_RU || isTransferOrderShipmentCancellation)
                             && qtyUpdate < 0)
                            || qtyUpdate > 0)
                        // </GEERU>
                    {
                        if (inventTransferParmTable.ExplodeLines)
                        {
                            while select forceplaceholders sum(Qty), sum(PdsCWQty)
                                from inventTrans
                                    group by InventTransOrigin,StatusIssue,StatusReceipt
                                    where inventTrans.InventTransOrigin == InventTransOriginTransferShip::findInventTransOriginId(inventTransferLine.DataAreaId, inventTransferLine.TransferId, inventTransferLine.LineNum)
                                    &&    inventTrans.StatusReceipt     == StatusReceipt::None
                                    // <GEERU>
                            &&  ((countryRegion_RU
                                          && ((qtyUpdate > 0
                                          &&   inventTrans.StatusIssue      >= StatusIssue::Picked)
                                          ||   (qtyUpdate < 0
                                          &&   inventTrans.StatusIssue      == StatusIssue::Sold
                                          &&   inventTrans.InvoiceReturned  == NoYes::No)))
                                          || (!countryRegion_RU
                                          && inventTrans.StatusIssue >= StatusIssue::Picked))
                                    // </GEERU>
                            join TableId from inventDim
                                    group by InventSerialId,InventBatchId,InventDimId
                                    where inventDim.InventDimId         == inventTrans.InventDimId
                            {
                                lineNum++;
                                inventTransferParmLine.clear();
                                this.initInventTransferParmLineFromInventTransferParmTable(inventTransferParmLine);
                                inventTransferParmLine.initFromInventTransferLine(inventTransferLine);
                                inventTransferParmLine.InventDimId      = inventDim.InventDimId;
                                this.initInventTransferParmLineFromInventTrans(inventTransferParmLine, inventTrans);
                                inventTransferParmLine.InventTransId        = inventTransferLine.InventTransId;
                                inventTransferParmLine.InventTransIdTransit = inventTransferLine.InventTransIdTransitTo;
                                // <GEERU>
                                if (countryRegion_RU)
                                {
                                    inventTransferParmLine.QtyShipNow           = abs(qtyUpdate) > -inventTrans.Qty ? -inventTrans.Qty * sign(qtyUpdate): qtyUpdate;
                                }
                                else
                                {
                                    // </GEERU>
                                    inventTransferParmLine.QtyShipNow           = qtyUpdate > -inventTrans.Qty ? -inventTrans.Qty : qtyUpdate;
                                    // <GEERU>
                                }
                                // </GEERU>
                                inventTransferParmLine.PdsCWQtyShipNow =
                                        cwQtyUpdate > -inventTrans.PdsCWQty
                                            ? -inventTrans.PdsCWQty
                                            : cwQtyUpdate;
                                inventTransferParmLine.LineNum              = lineNum;
                                inventTransferParmLine.insert();
                                qtyUpdate -= inventTransferParmLine.QtyShipNow;
                                // <GEERU>
                                if (qtyUpdate == 0
                                        || (!countryRegion_RU
                                            && qtyUpdate < 0)
                                        || (PdsGlobal::pdsIsCWItem(inventTransferLine.ItemId) && (cwQtyUpdate <= 0)))
                                    // </GEERU>
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            lineNum++;
                            inventTransferParmLine = this.createShipLineWithoutExplodeLines(inventTransferTable, inventTransferLine, lineNum, qtyUpdate, cwQtyUpdate);
                        }
                    }
                }
                // <GEERU>
            }
            else
            {
                while select TransferId, LineNum, InventDimId, QtyShipped from inventTransferJourLine            // lines are always exploded
                    where inventTransferJourLine.TransferId  == inventTransferParmTable.TransferId        &&
                          inventTransferJourLine.VoucherId   == inventTransferParmTable.VoucherShipmentId
                {
                    inventTransferLine = InventTransferLine::find(inventTransferJourLine.TransferId,inventTransferJourLine.LineNum);
                    if (this.mustSkipInventTransferLine(InventTransferLine))
                    {
                        continue;
                    }
                    lineNum++;
                    inventTransferParmLine.clear();
                    this.initInventTransferParmLineFromInventTransferParmTable(inventTransferParmLine);
                    inventTransferParmLine.initFromInventTransferLine(inventTransferLine);
                    inventTransferParmLine.InventDimId          = inventTransferJourLine.InventDimId;
                    inventTransferParmLine.InventTransId        = inventTransferLine.InventTransId;
                    inventTransferParmLine.InventTransIdTransit = inventTransferLine.InventTransIdTransitTo;
                    inventTransferParmLine.QtyShipNow           = - inventTransferJourLine.QtyShipped;
                    inventTransferParmLine.LineNum              = lineNum;
                    inventTransferParmLine.insert();
                }
            }
            // </GEERU>
            ttscommit;
     
     
    Hope this helps. Happy to answer questions, if any. 
     
     
  • Waed Ayyad Profile Picture
    Waed Ayyad 6,241 Super User 2024 Season 2 on at
    how can i ship the transfer order using x++ code
    Hi Dinesh,
     
    Can you explain your issue on more details? Did you debug the code? Which status was changed?
     
     
    Thanks
    Waed Ayyad
  • Layan Jwei Profile Picture
    Layan Jwei 7,339 Super User 2024 Season 2 on at
    how can i ship the transfer order using x++ code
    Hi Dinesh,

    I can't understand what is the issue can you please explain again and share your final code please
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    how can i ship the transfer order using x++ code
    hi ,
    thanks for reply ,
    I am getting the transfer order shipped for single line ,
    but i need it to do for multiple lines also , can you help me on this , i have added extra line in code and it worked but the shipped status is updated on header level on my code so i need to run the shipped code when all the lines are inserted in transfer order .
        inventTransferLine.UnderDeliveryPct = 100;
    thanks ,
    Regards,
    Dinesh 
  • Layan Jwei Profile Picture
    Layan Jwei 7,339 Super User 2024 Season 2 on at
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    how can i ship the transfer order using x++ code
    hi , everyone 
     
    I have tried to ship the transfer order but getting error when doing shipment below is my code can u please suggest me what changes i have to make .
      public void run(InventSum  inventSum = null)
        {
            InventTransferParmTable     invTransParmTbl;
            InventTransferUpd           invTranUpd;
            InventDim     inventDim,inventDim1,inventDim2;
          
            if(!map.exists(inventSum.InventLocationId))
            {
                inventTransferTable.clear();
                inventTransferTable.initvalue();
    
                numbersequencereference = inventparameters::numreftransferid();
                numberseq = numberseq::newgetnumfromcode(numbersequencereference.numbersequencetable().numbersequence);
                //TransferId = numberseq.num();
                inventTransferTable.transferid = numberseq.num();//TransferId;
                inventTransferTable.inventlocationidfrom = inventSum.InventLocationId;
                inventTransferTable.modifiedfield(fieldnum(inventTransferTable, inventlocationidfrom));
                inventTransferTable.inventlocationidto = getToWarehouse;
                inventTransferTable.modifiedfield(fieldnum(inventTransferTable, inventlocationidto));
                inventTransferTable.transferstatus = inventtransferstatus::created;
                inventTransferTable.insert();
    
                select InventLocationId from inventDim
                    where inventDim.inventDimId == inventSum.InventDimId;
    
                Map.insert(inventDim.InventLocationId,inventTransferTable);
                if(TransferOrderList == '')
                {
                    TransferOrderList = inventTransferTable.transferid;
                    cnt++;
                }
                else
                {
                    TransferOrderList = strReplace(TransferOrderList," and ",", ");
                    TransferOrderList = TransferOrderList + " and " + inventTransferTable.transferid;
                    cnt++;
                }
                inventTransferLine.clear();
                inventTransferLine.ItemId   =   inventSum.ItemId;
                inventTransferLine.initfrominventtable(inventtable::find(inventTransferLine.ItemId));
                inventTransferLine.initfrominventTransferTable(inventTransferTable, NoYes::Yes);
                inventTransferLine.qtytransfer  =   inventSum.AvailPhysical;
                inventTransferLine.qtyremainreceive =   1;
                inventTransferLine.qtyremainship    =  1;
                inventTransferLine.inventdimid  =   inventSum.inventdimid;
                inventTransferLine.LineNum  =   1;
                inventTransferLine.insert();
    
                invTransParmTbl.TransferId = inventTransferTable.TransferId;
                invTransParmTbl.EditLines = true;
                invTransParmTbl.AutoReceiveQty = false;
                invTransParmTbl.UpdateType = InventTransferUpdateType::Shipment;
                invTransParmTbl.ShipUpdateQty = InventTransferShipUpdateQty::All;
                invTransParmTbl.TransDate = systemDateGet();
     
                invTranUpd = InventTransferUpdShip::newParmBuffer(invTransParmTbl);
                invTranUpd.run();
     
                Info("Transfer Order: " + inventTransferTable.TransferId + " is Shipped.");
            }
            else
            {
                inventTransferTable.clear();
    
                select InventLocationId from inventDim1
                    where inventDim1.inventDimId == inventSum.InventDimId;
    
                inventTransferTable = map.lookup(inventDim1.InventLocationId);
                inventTransferLineLoc.clear();
    
                select firstonly LineNum from inventTransferLineLoc
                    order by inventTransferLineLoc.LineNum desc
                    where inventTransferLineLoc.TransferId == inventTransferTable.TransferId;
    
                inventTransferLine.clear();
                inventTransferLine.ItemId = inventSum.ItemId;
                inventTransferLine.initfrominventtable(inventtable::find(inventTransferLine.ItemId));
                inventTransferLine.initfrominventTransferTable(inventTransferTable, NoYes::Yes);
                inventTransferLine.qtytransfer = inventSum.AvailPhysical;
                inventTransferLine.qtyremainreceive = 1;
                inventTransferLine.qtyremainship = 1;
                inventTransferLine.inventdimid = inventSum.inventdimid;
                inventTransferLine.LineNum  =   inventTransferLineLoc.LineNum + 1;
                inventTransferLine.insert();
            }
    
        }
     
  • Layan Jwei Profile Picture
    Layan Jwei 7,339 Super User 2024 Season 2 on at
    how can i ship the transfer order using x++ code
    Hi Dinesh,
     
    Is your question answered or do u still need help?
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 6,241 Super User 2024 Season 2 on at
    how can i ship the transfer order using x++ code
    Hi Dinesh,
     
    Check out this blog; it may be helpful for you:
     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
     
  • Suggested answer
    Layan Jwei Profile Picture
    Layan Jwei 7,339 Super User 2024 Season 2 on at
    how can i ship the transfer order using x++ code
    Hi Dinesh,
     
    You can manually ship it and debug the code to see what is being called then reflect that to your code.
     
    Maybe check if this link helps, as it contains at the end of it, some code related to making it shipped
     
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    how can i ship the transfer order using x++ code
    hi 
    Below is my code which create the new transfer please suggest me what modification i need to do in my code to make the transfer order shipped.
       public void run(InventSum  inventSum = null)
        {
    
            InventDim     inventDim,inventDim1,inventDim2;
            //info(strFmt("%1 ;%2; %3; %4; %5",dtInventorySearch.inventSerialId,dtInventorySearch.ItemId,dtInventorySearch.configId,dtInventorySearch.InventLocationId,dtInventorySearch.InventDimId));
    
            if(!map.exists(inventSum.InventLocationId))
            {
                inventTransferTable.clear();
                inventTransferTable.initvalue();
    
                numbersequencereference = inventparameters::numreftransferid();
                numberseq = numberseq::newgetnumfromcode(numbersequencereference.numbersequencetable().numbersequence);
                //TransferId = numberseq.num();
                inventTransferTable.transferid = numberseq.num();//TransferId;
                inventTransferTable.inventlocationidfrom = inventSum.InventLocationId;
                inventTransferTable.modifiedfield(fieldnum(inventTransferTable, inventlocationidfrom));
                inventTransferTable.inventlocationidto = getToWarehouse;
                inventTransferTable.modifiedfield(fieldnum(inventTransferTable, inventlocationidto));
                inventTransferTable.transferstatus = inventtransferstatus::created;
                inventTransferTable.insert();
    
                select InventLocationId from inventDim
                    where inventDim.inventDimId == inventSum.InventDimId;
    
                Map.insert(inventDim.InventLocationId,inventTransferTable);
                if(TransferOrderList == '')
                {
                    TransferOrderList = inventTransferTable.transferid;
                    cnt++;
                }
                else
                {
                    TransferOrderList = strReplace(TransferOrderList," and ",", ");
                    TransferOrderList = TransferOrderList + " and " + inventTransferTable.transferid;
                    cnt++;
                }
                inventTransferLine.clear();
                inventTransferLine.ItemId   =   inventSum.ItemId;
                inventTransferLine.initfrominventtable(inventtable::find(inventTransferLine.ItemId));
                inventTransferLine.initfrominventTransferTable(inventTransferTable, NoYes::Yes);
                inventTransferLine.qtytransfer  =   inventSum.AvailPhysical;
                inventTransferLine.qtyremainreceive =   1;
                inventTransferLine.qtyremainship    =  1;
                inventTransferLine.inventdimid  =   inventSum.inventdimid;
                inventTransferLine.LineNum  =   1;
                inventTransferLine.insert();
            }
            else
            {
                inventTransferTable.clear();
    
                select InventLocationId from inventDim1
                    where inventDim1.inventDimId == inventSum.InventDimId;
    
                inventTransferTable = map.lookup(inventDim1.InventLocationId);
                inventTransferLineLoc.clear();
    
                select firstonly LineNum from inventTransferLineLoc
                    order by inventTransferLineLoc.LineNum desc
                    where inventTransferLineLoc.TransferId == inventTransferTable.TransferId;
    
                inventTransferLine.clear();
                inventTransferLine.ItemId = inventSum.ItemId;
                inventTransferLine.initfrominventtable(inventtable::find(inventTransferLine.ItemId));
                inventTransferLine.initfrominventTransferTable(inventTransferTable, NoYes::Yes);
                inventTransferLine.qtytransfer = inventSum.AvailPhysical;
                inventTransferLine.qtyremainreceive = 1;
                inventTransferLine.qtyremainship = 1;
                inventTransferLine.inventdimid = inventSum.inventdimid;
                inventTransferLine.LineNum  =   inventTransferLineLoc.LineNum + 1;
                inventTransferLine.insert();
            }
    
        }
    thanks,
    regards,
    Dinesh

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,219 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans