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 :
Finance | Project Operations, Human Resources, ...
Answered

How to cancel Purchase order line through x++ in D365fo

(0) ShareShare
ReportReport
Posted on by 2,426

Good morning,

As i have requirement to cancel PO line through code.

i have found in internet this piece of code.

void cancelPurchLine(recId PurchLineRecId)
{
    PurchLine       localPurchLine = PurchLine::findRecId(PurchLineRecId,true);
    ;
    ttsbegin;
 
    localPurchLine.RemainPurchPhysical = 0;
    localPurchLine.RemainInventPhysical = 0;
 
    localPurchLine.update();
 
    ttscommit;
}

is this the correct way.

Please show some light on this.

Regards,

Have a nice day.

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,429 on at

    Hi AX 2012 r3,

    What do you mean by cancelling Purchase order lines? Purchase orders can be cancelled. This means all the purchase order lines linked to the PO are cancelled as well. Or are you looking to cancel the lines in product receipt?

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,097 on at

    Hi Ax 2012 r3,

    This code should work and additionally, you can empty PdsCWRemainInventPhysical field.

    Check how test for cancel line is designed in test class (AtlEntityPurchaseOrderLine.cancelLine)

  • Suggested answer
    Sukrut Parab Profile Picture
    71,741 Moderator on at

    Your above code should work , in fact you can refer deliver remainder  functionality uses similar code to cancel the quantity , You can  refer that code to confirm.

  • AX 2012 r3 Profile Picture
    2,426 on at

    Hi all,

    Thanks for your quick replies.

    I appreciate your help.

    My requirement is in intercompany

    Sales order --> Purchase order.

    Now some one changed site in salesline from 1 to 2.

    Then i have to cancel related Intercompany Purchase order line.

    I found the above code in internet

    pastedimage1603133177605v1.png

    Navigation - PO line -> Update line -> Update -> Deliver remainder -> Cancel Quantity.

    I checked in form code.

    Step - 1 :

    pastedimage1603133360014v2.png

    Step - 2 :

    pastedimage1603133424399v3.png

    Below that

    pastedimage1603133461337v4.png

    There is code related to intercompany in my scenario should i include this code  ?

    pastedimage1603133556712v5.png

    In my scenario what can i include.

    Please show some light on this.

    Regards,

    Have a nice day.

  • Suggested answer
    Sukrut Parab Profile Picture
    71,741 Moderator on at

    The above highlighted code is nothing but the code you shared its just taking the value from the form control and setting it . You can implement  the code and try testing your scenario and see if it covers all your scenario.

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 Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 433 Super User 2026 Season 1

#2
Subra Profile Picture

Subra 382

#3
Martin Dráb Profile Picture

Martin Dráb 279 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans