cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
James_Baibai
Regular Visitor

How to delete in batch

Hello, I am a newcomer to Power Platform. I plan to fulfill the requirement of batch deletion. To be specific, I would like to write a plugin with c# in Visual Studio. I provide a template with the column including the product ID, terminal ID, external ID, and operation to users. The user can export the template. When a user writes "D"(stands for delete) in the column of operation. It will trigger our plugin to delete the corresponding record. And then, the user can import the excel to dataverse(CDS). My question is how to write the plugin. Could you please give me some hints or references. Appreciate your help.

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisPiasecki
Super User
Super User

Hi @James_Baibai,

 

Have you assessed the true need to allow your users to bulk delete? Once the records are deleted they are gone, the only way to retrieve the data is if auditing was enabled on all the fields or if you restore from a backup, which only retain up to 7 days for production databases. I find that it's much safer to deactivate records once they are no longer required. That said, if you want to allow Bulk Deletion, you should have a look at out of box Bulk Deletion jobs to see if it can meet your needs. If you don't need the records to be deleted in real time / near-real time, you could setup a bulk deletion job to run nightly to delete records based off criteria you define. In your example you could have the users set a certain status on the records and import those updates back into Dataverse, then your next bulk deletion run would delete those records based on the status. The benefit of this is that you don't have to grant those users delete permissions, reducing risk of inadvertent deletion, but still provide a controlled process to actually delete the records. 

 

There is also the Bulk Data Updater for the Xrmtoolbox which allows you to bulk delete using views and FetchXml queries. 

 

If you still prefer to write your own code to do deletion, you can refer to this reference on how to achieve this using the .NET SDK. 

 

---
Please click Accept as Solution if my post answered your question. This will help others find solutions to similar questions. If you like my post and/or find it helpful, please consider giving it a Thumbs Up.

 

 

 

View solution in original post

3 REPLIES 3
ChrisPiasecki
Super User
Super User

Hi @James_Baibai,

 

Have you assessed the true need to allow your users to bulk delete? Once the records are deleted they are gone, the only way to retrieve the data is if auditing was enabled on all the fields or if you restore from a backup, which only retain up to 7 days for production databases. I find that it's much safer to deactivate records once they are no longer required. That said, if you want to allow Bulk Deletion, you should have a look at out of box Bulk Deletion jobs to see if it can meet your needs. If you don't need the records to be deleted in real time / near-real time, you could setup a bulk deletion job to run nightly to delete records based off criteria you define. In your example you could have the users set a certain status on the records and import those updates back into Dataverse, then your next bulk deletion run would delete those records based on the status. The benefit of this is that you don't have to grant those users delete permissions, reducing risk of inadvertent deletion, but still provide a controlled process to actually delete the records. 

 

There is also the Bulk Data Updater for the Xrmtoolbox which allows you to bulk delete using views and FetchXml queries. 

 

If you still prefer to write your own code to do deletion, you can refer to this reference on how to achieve this using the .NET SDK. 

 

---
Please click Accept as Solution if my post answered your question. This will help others find solutions to similar questions. If you like my post and/or find it helpful, please consider giving it a Thumbs Up.

 

 

 

View solution in original post

EricRegnier
Super User II
Super User II

Hi @James_Baibai, as @ChrisPiasecki mentioned, bulk delete jobs would be the way to go with out-of-the-box capabilities and no code. You can schedule the job to run nightly (or even more frequently) based on the "D" column. Cheers

Fubar
Solution Sage
Solution Sage

As per the others, sounds like a job for bulk delete - unless you need it removed immediately (i.e. not on a schedule).

Personally, I would include a field (probably what you are referring to as the operation), and another Status Reason 'Delete' to the Inactive status, and have a Workflow or Flow trigger on update of that field and set the record set the record to the Delete status reason.  Then run a bulk delete job to remove all records with status reason = Delete (nightly etc).  The benefit of the new status reason, is that if provides time for someone to realize they made a mistake and undo it - as deleting is removing permanently.

https://docs.microsoft.com/en-us/power-platform/admin/delete-bulk-records

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Users online (67,628)