Recently I had a requirement where my customer wanted to remove delete privilege for all regular business roles from Note entity. There is no big thing in this. All you need is open up the security role and under “Core Records” tab, remove the delete privilege on the Note Entity.
As expected when the user will go ahead and try to delete a note, he will not see the delete button. However if a note has attachment, the user can still go, delete the attachment and save the note.
Why is that so? This is because behind the scenes, attachment is stored in field (document body) of note entity and when you delete an attachment from note, it is basically an update operation. Since the user have edit privilege on the record.
But my customer wanted to stop the delete of attachment from note. So what are the options?
Well the easiest one is to write a plugin on pre-create of Note (schemname – annotation). Set filtering attribute as – Document (documentbody) as shown in the below screenshot. That’s all from the configuration side.
Below is the sample code to now check if the attachment is being deleted and then taking appropriate action.
While you check for documentbody value, don’t check it for just null condition. The reason is when you delete the document, document body may come in as empty string and your check will fail.
Kind of common requirement from customers I see these days and hence thought of sharing.
Hope this helps!
Our product offerings:
Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)
CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)
Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)
Multiselect picklist for Dynamics 365 (http://www.xrmforyou.com/multi-select-picklist.html)