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

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

(0) ShareShare
ReportReport
Posted on by 2,420

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.

  • Suggested answer
    Sukrut Parab Profile Picture
    71,637 Moderator on at
    RE: How to cancel Purchase order line through x++ in D365fo

    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.

  • AX 2012 r3 Profile Picture
    2,420 on at
    RE: How to cancel Purchase order line through x++ in D365fo

    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,637 Moderator on at
    RE: How to cancel Purchase order line through x++ in D365fo

    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.

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,083 on at
    RE: How to cancel Purchase order line through x++ in D365fo

    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)

  • Gunjan Bhattachayya Profile Picture
    35,417 on at
    RE: How to cancel Purchase order line through x++ in D365fo

    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?

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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,860 Test role Public

#2
Ludwig Reinhard Profile Picture

Ludwig Reinhard Microsoft Employee

#3
Martin Dráb Profile Picture

Martin Dráb 225,155 Moderator

Leaderboard

Product updates

Dynamics 365 release plans