web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Creating purchase line using x++ code

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    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.  

  • Suggested answer
    Hossein.K Profile Picture
    6,650 on at
    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();
     
    }

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 21

#2
dekion Profile Picture

dekion 4

#2
Virginia99 Profile Picture

Virginia99 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans