How to delete record/field value using the Web API in Dynamics CRM

By | April 15, 2016


As we all know, the Web API has been introduced in Microsoft Dynamics CRM 2016. It offers a great development experience across many devices, programming languages and platforms.

In our earlier blog, we have seen how to create and retrieve records using the Web API. Now, let’s take a look of how to delete a Lookup field value in CRM.

Clear Entity Reference [Lookup] Field Value:

We are trying to Clear the lookup field value or set the value of the lookup field as null using the Patch action but it does not work as expected. So there is an alternate way to clear the lookup field value by using the DELETE action.

If we need to clear the lookup field value using DELETE action then we need to pass the Record GUID with the logical name of lookup field along with the ‘$ref’ keyword.

Here’s is the code snippet.

Later, the above code is used to clear/delete the entity reference (lookup) field value. To specify the field is lookup field, we need to use entity reference ‘/$ref’ after the field name.

Delete String/Date/OptionSet/Currency Field Value:

We can also clear the single entity attribute value of type string/Date/Option Set/Currency using the DELETE action. To perform this action we need to pass the field’s logical name and the record GUID in the Web API URL section. Here’s is the code which will help you understand what we are trying to say.

From the above code the ‘Phone (telephone1)’ field value from the account record will be cleared.

Deleting an Entity Record:

Let’s consider ‘Accounts’ as the entity for which the record needs to be deleted. You have to pass the record GUID as a parameter in the WEB API URL in order to delete the entity record.

Check out the code as written below.


On a concluding note, it is actually simple to delete an entity record using Web API. You should ensure that the right record GUID and the field’s logical name are passed as parameters.

Before moving to the next post, Have a look at Maplytics InfoCentre, everything under one roof.

Leave a Reply

Your email address will not be published. Required fields are marked *