Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Purchase order Auto Create From Sales Order than Post as a Packing Slip

(0) ShareShare
ReportReport
Posted on by 1,879

Dears,

I successfully converted Sales order to Purchase order with below code. But I don't understand where I can mention Packing-slip update(PurchFormLetter) method in below code to Post as packing slip for PO once PO is created.

SO001177static void Job5(Args _args)
{
TmpPurchLinePrice tmpPurchLinePrice;
PurchCreateFromSalesOrder PurchCreateFromSalesOrder;
PurchAutoCreate purchAutoCreate;
VendAccount prevVendAccount;
SalesTable salesTable;
SalesLine salesLine;
PurchTable purchTable;    
PurchFormLetter  purchFormLetter;
LineNum lineNumber = 0;
;

try
{
 ttsbegin;
   while select *from salesLine where salesLine.SalesId == "SO001177"
    {

salesTable = salesLine.salesTable();
purchCreateFromSalesOrder = PurchCreateFromSalesOrder::construct();
purchCreateFromSalesOrder.parmCallerRecord(salesTable);
tmpPurchLinePrice.clear();
lineNumber  = 1;
tmpPurchLinePrice.SalesId = salesLine.SalesId;
tmpPurchLinePrice.LineNum = lineNumber;
tmpPurchLinePrice.SalesLineRefRecId = salesLine.RecId;
tmpPurchLinePrice.AccountNum = "V000070";
tmpPurchLinePrice.ItemId = salesLine.ItemId;
tmpPurchLinePrice.InventDimId = salesLine.InventDimId;
tmpPurchLinePrice.Included = NoYes::Yes;
tmpPurchLinePrice.PurchQty = salesLine.SalesQty;
tmpPurchLinePrice.QtyOrdered = salesLine.QtyOrdered;
tmpPurchLinePrice.PurchUnit = salesLine.SalesUnit;
tmpPurchLinePrice.PriceUnit = salesLine.PriceUnit;
tmpPurchLinePrice.CurrencyCode = salesLine.CurrencyCode;
tmpPurchLinePrice.LineAmount =  salesLine.LineAmount;
tmpPurchLinePrice.LineDisc  = salesLine.LineDisc;
tmpPurchLinePrice.LinePercent = salesLine.LinePercent;
tmpPurchLinePrice.MultiLineDisc = salesLine.MultiLnDisc;
tmpPurchLinePrice.MultiLinePercent = salesLine.MultiLnPercent;
tmpPurchLinePrice.Markup = salesLine.SalesMarkup;
tmpPurchLinePrice.insert();
    }
 purchCreateFromSalesOrder.parmTmpPurchLinePrice(tmpPurchLinePrice);
 purchCreateFromSalesOrder.parmSalesTable(salesTable);
 purchCreateFromSalesOrder.tradeLineDlvType(tradeLineDlvType::None);
 purchCreateFromSalesOrder.run();
 

  ttscommit;
  info("Success");
 }

catch (Exception::Error)
{
ttsabort;
}
}

Thanks

  • Faqruddin Profile Picture
    Faqruddin 1,879 on at
    RE: Purchase order Auto Create From Sales Order than Post as a Packing Slip

    Thanks Harish. For normal Sales order below code is working. But if I have a project Id assign to SO than below warning is prompted.

    You cannot specify a project after the record has been saved.

    static void Job5(Args _args)
    {
    TmpPurchLinePrice tmpPurchLinePrice;
    PurchCreateFromSalesOrder PurchCreateFromSalesOrder;
    PurchAutoCreate purchAutoCreate;
    VendAccount prevVendAccount;
    SalesTable salesTable;
    SalesLine salesLine;
    PurchTable purchTable;    
    PurchFormLetter  purchFormLetter;
    LineNum lineNumber = 0;
    ;
    
    try
    {
     ttsbegin;
       while select *from salesLine where salesLine.SalesId == "SO001180"
        {
    
    salesTable = salesLine.salesTable();
    purchCreateFromSalesOrder = PurchCreateFromSalesOrder::construct();
    purchCreateFromSalesOrder.parmCallerRecord(salesTable);
    tmpPurchLinePrice.clear();
    lineNumber  = 1;
    tmpPurchLinePrice.SalesId = salesLine.SalesId;
    tmpPurchLinePrice.LineNum = lineNumber;
    tmpPurchLinePrice.SalesLineRefRecId = salesLine.RecId;
    tmpPurchLinePrice.AccountNum = "V000070";
    tmpPurchLinePrice.ItemId = salesLine.ItemId;
    tmpPurchLinePrice.InventDimId = salesLine.InventDimId;
    tmpPurchLinePrice.Included = NoYes::Yes;
    tmpPurchLinePrice.PurchQty = salesLine.SalesQty;
    tmpPurchLinePrice.QtyOrdered = salesLine.QtyOrdered;
    tmpPurchLinePrice.PurchUnit = salesLine.SalesUnit;
    tmpPurchLinePrice.PriceUnit = salesLine.PriceUnit;
    tmpPurchLinePrice.CurrencyCode = salesLine.CurrencyCode;
    tmpPurchLinePrice.LineAmount =  salesLine.LineAmount;
    tmpPurchLinePrice.LineDisc  = salesLine.LineDisc;
    tmpPurchLinePrice.LinePercent = salesLine.LinePercent;
    tmpPurchLinePrice.MultiLineDisc = salesLine.MultiLnDisc;
    tmpPurchLinePrice.MultiLinePercent = salesLine.MultiLnPercent;
    tmpPurchLinePrice.Markup = salesLine.SalesMarkup;
    tmpPurchLinePrice.insert();
        }
    // purchCreateFromSalesOrder.parmTmpPurchLinePrice(tmpPurchLinePrice);
     //purchCreateFromSalesOrder.parmSalesTable(salesTable);
     //purchCreateFromSalesOrder.tradeLineDlvType(tradeLineDlvType::None);
    // purchCreateFromSalesOrder.run();
       purchAutoCreate = PurchAutoCreate::construct(tmpPurchLinePrice, purchCreateFromSalesOrder);
       purchAutoCreate.create();
        
        
        purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);// PO confirm
        purchformLetter.update(purchAutoCreate.parmPurchTable(), purchAutoCreate.purchId());
        info(strFmt("%1 PO is Confirmed ",purchAutoCreate.purchId()));
    
    
        purchformletter = PurchFormLetter::construct(DocumentStatus::PackingSlip);// PackingSlip
        purchformletter.update(purchAutoCreate.parmPurchTable(), purchAutoCreate.purchId());
        info(strFmt("%1 PO PackingSlip created  ",purchAutoCreate.purchId()));
    
      ttscommit;
     
     }
    
    catch (Exception::Error)
    {
    ttsabort;
    }
    }

  • Verified answer
    Hariharans87 Profile Picture
    Hariharans87 on at
    RE: Purchase order Auto Create From Sales Order than Post as a Packing Slip

    I guess your code will create only the PO draft not confirmed PO. So, once PO created, confirm the PO and do the packing slip by code.

    You may not get the PO id if you call the PurchCreateFromSalesOrder.run(). So try the code as like www.axpulse.com/.../

    You can get purchase id by calling this method, purchAutoCreate.purchId().

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans