Dynamics 365 - Set Null Value For All Data Types Using C#

Introduction

Recently we had a requirement to set null value for all data types field from C# as part of our integration.

I tried searching on the internet but couldn't find proper documentation or sample code for all data types field. So I decided to try using console utility and also wanted to share with CRM communities.

Sample Code Snippet

Entity objLead = new Entity("lead");
objLead.Id = Guid.Parse("Record GUID");
//Currency
//objLead["ims_loanamount"] = null;
//Decimal
//objLead["ims_loanrate"] = null;
//Datetime
//objLead["ims_birthday"] = null;
//optionset
//objLead["ims_gender"] = null;
//WholeNumber
//objLead["ims_creditscore"] = null;
//Lookup
//objLead["ims_loantype"] = null;
//Two Optionset
//objLead["ims_firsttimebuyer"] = null;
_orgservice.Update(objLead);

Conclusion

I have provided sample code to set value to different data types from C# code for Dynamics CRM.

Hope this helps!

Happy CRMing!