Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Delete all opportunity product line items in opportunity

(0) ShareShare
ReportReport
Posted on by 45

Hello,

I am looking for a way to allow the user to delete all product line items in an opportunity in one go.

Does anyone know how this can be accomplished please.

Currently they have to delete it line by line with the trash can icon on each line.

Appreciate the assistance.

*This post is locked for comments

  • e0209 Profile Picture
    45 on at
    RE: Delete all opportunity product line items in opportunity

    I'm close to being successful on this. 

    Created a button using RibbonWorkbench and set it to ran a javascript in webresource.

    Currently using the v9 code suggested at https://arunpotti.wordpress.com/tag/crm-delete-record/ and changing opportunityproduct.

    It works if I feed it the GUID of the opportunityproduct within the opportunity 

    function DeleteRecord() {
     // Delete Account record
     Xrm.WebApi.deleteRecord("opportunityproduct", "9C36DC38-79E9-E711-A95E-000D3AF27CC8").then(
     function success(result) {
     // Perform operations on record deletion
     Xrm.Utility.alertDialog("Account deleted", null);
     },
     function (error) {
     // Handle error conditions
     Xrm.Utility.alertDialog(error.message, null);
     });
    }
    

    How can I dynamically fetch the list of GUIDs of all opportunityproducts within the opportunity and pass it in the required format to the Xrm.WebApi.deleteRecord function to delete all opportunityproducts within the opportunity?

    Appreciate any assistance.

  • e0209 Profile Picture
    45 on at
    RE: Delete all opportunity product line items in opportunity

    Awesome Pravin! Will look through the links you have shared.

    Appreciate your assistance and have a good weekend ahead.

  • Verified answer
    Pawar Pravin  Profile Picture
    5,237 on at
    RE: Delete all opportunity product line items in opportunity

    Hi ,

    Please do follow steps as given:

    1. Create custom button on opportunity using ribbon workbench or ribbon editor

    ribbonworkbench.uservoice.com/.../358664-create-a-command-bar-button-for-your-custom-acitiv

    2. Call js/ plugin on button click using command action but make sure that should be synchronous

    (For plugin either use background flag or custom action)

    sasankkomarina.wordpress.com/.../delete-record-plugin-in-crm-2011

    a2zcrmstuff.blogspot.com/.../mscrm-javascript-delete-record-using.html

    arunpotti.wordpress.com/.../crm-delete-record

    https://www.inogic.com/blog/2016/04/how-to-delete-recordfield-value-using-the-web-api-in-dynamics-crm/

  • Suggested answer
    Adrian Begovich Profile Picture
    1,025 Super User 2025 Season 1 on at
    RE: Delete all opportunity product line items in opportunity

    Hi e0209,

    You can create a custom button with the Ribbon Workbench for Dynamics 365 & Dynamics CRM.

  • e0209 Profile Picture
    45 on at
    RE: Delete all opportunity product line items in opportunity

    Thanks Pravin, that sounds like a viable solution.

    Do you have any resources/tutorials and plugins/js you have come across which you can share on creating custom button to do this?

    Appreciate your response :)

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at
    RE: Delete all opportunity product line items in opportunity

    Hi,

    I can suggest you as in case of if they want to delete all product line items of respective opportunity you need to create one custom button on opportunity called as as "Delete Products".

    On that button you can call synchronous js/plugin to delete related all product items.

  • e0209 Profile Picture
    45 on at
    RE: Delete all opportunity product line items in opportunity

    Thank you Adrian for your reply.

    However I am not removing large amounts of product line records.

    It's just for the convenience of the user to remove all products (probably 5 to 10 lines each time they use it) and reuse the opportunity to add products to get latest pricing.

  • Suggested answer
    Adrian Begovich Profile Picture
    1,025 Super User 2025 Season 1 on at
    RE: Delete all opportunity product line items in opportunity

    Hi e0209,

    I recommend using the Bulk Record Deletion feature for removing large amounts of product line records.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans