Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Creating purchase line using x++ code

Posted on by 180

Hi guys,

I encountered an error during creating purchase lines using x++ code. The error is "The purchase lines cannot be created because the purchase order has been finalized.". How can I solve this case? I used this code in creating purchase lines:

purchLine.createLine(true, true, true, true, true, false);

Thank you.

BR,

Ron

*This post is locked for comments

  • Suggested answer
    Hossein.K Profile Picture
    Hossein.K 6,642 on at
    RE: Creating purchase line using x++ code
    void clicked()
    {
        PurchTable  purchTable;
        PurchLine   purchLine;
        InventDim   inventDim;
        NumberSeq   numberSeq;
     
        //add by fanddy
        AxPurchTable    axPurchTable;
        AxPurchLine     axPurchLine;
        PurchFormLetter purchformLetter;
        //END
     
       //create PO Header
       purchTable.clear();
       purchTable.initFromVendTable(VendTable::find(TECPOGroupHeader.VendAccount));
       purchTable.DefaultDimension = InventTable::find(POGroupLine.ItemId).DefaultDimension;
     
       axPurchTable = axPurchTable::newPurchTable(purchTable);
       axPurchTable.parmPurchId(NumberSeq::newGetNum(PurchParameters::numRefPurchId()).num());
       axPurchTable.parmPurchaseType(PurchaseType::Purch);
       axPurchTable.parmDocumentStatus(DocumentStatus::PurchaseOrder);
       axPurchTable.parmAccountingDate(systemDateGet());
       axPurchTable.parmDeliveryDate(systemDateGet());
       axPurchTable.parmPurchStatus(PurchStatus::Backorder);
       axPurchTable.save();
     
       info(strFmt('Create PO %1', Purchtable.PurchId));
     
       //create PO Line
       purchLine.clear();
       purchLine.initValue();
       purchLine.initFromPurchTable(purchTable);
       purchLine.initFromInventTable(InventTable::find(POGroupLine2.ItemId));
       axPurchLine = AxPurchLine::newPurchLine(purchLine);
       axpurchLine.parmItemId('YOUR ITEMID');
       axPurchLine.parmPurchQty(YOUR QTY);
       axPurchLine.parmPurchPrice(YOUR PRICE);
       axPurchLine.parmInventDimId('YOUR INVENTDIMID');
       axPurchLine.save();
     
    }
  • Verified answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: Creating purchase line using x++ code

    Hi ron_ron,

    This Purchase order cannot be changed because of it's status, so you cannot add new PO line to it. Pick different PO, it's not an issue in your code, it's just finalized PO you trying to change.  

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!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans