Stop - Prevent deletes while still allowing deletes

July 24, 2018

 

 

Deleting records. There are times where you need to delete records and there are times when you don’t want to delete records. I’m an advocate of only giving responsible users the deletion if I have to give it to users at all. Sometimes, against my better advice, people want to give all users on a certain team the ability to delete records but prevent the from deleting certain records.

 

I’ve had some projects in the past where part of their business processes involved default accounts/contacts or other records so we had to give users the ability to delete other records in these entities while not deleting specific records. Urgh! That’s not the way security roles work.

 

You could go down the route of different business units and adjusting the security roles but that seems like a right pain. There is a better solution, real-time workflows which run before  a record is changed.

 

First thing we need to do is decide how we want to determine records which should not be deleted, i’ve decided in my example to create a two-option, option set and enable field security. This allows you to control who has access to this field to read, write and on create.

 

Create your field like the picture below and place it on your form.

 

 

Next you want to create a field security profile. Go to Settings -> Security, create a new Field Security Profile and save the record.

 

 

 

Add your users and/or teams you want access to change these settings N.b remember System Admins will automatically gain access to this field through their elevated permissions.

 

Next, go to the Field Permissions tab and find the field you have just created. Either double click it or select and click edit. Update the permissions to give users the ability to read, write and if you want, create as well. Save the Field Security Profile.

 

 

 

We now need to create our real-time workflow.

 

 

 

On your workflow configuration screen, change the settings for when the workflow triggers to enabled for delete and ensure the selector is set to Before and not After. This will trigger the workflow before the record is deleted.

 

 

 

Put in a check condition to check the data in the field we just created, so in my example check if Prevent Delete = Yes.

 

 

 

Now we need to stop the workflow as Cancelled...sorry, that should read Canceled. :)

 

 

 

Set the properties on this step in the workflow and put in a message to be presented back to the user.

 

 

 

Save and activate the workflow. Go to a Contact record and test by trying to delete.

 

 

 

There you have it, but this doesn’t just stop you from deleting records, it has other applications too! Preventing a case from being closed if the customer has not paid for a replacement part, additional checks that opportunities have been updated correctly before moving to the next stage of a Business Process flow; this same technique can be applied in multiple ways.

 

Ciao for now!

 

Please reload

Recent Posts

Please reload

Archive

Please reload

Tags

D365 Blog by Matt. ©2018