Dynamics 365 Sample Code to set null value for all data types using c#

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 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 Snipped

                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);

Hope this helps!

Happy CRMing

Comments

Popular posts from this blog

Tips 01) self introduction in an interview

Computer Science Terminology

Dynamics 365 Error #2 Object reference not set to an instance of an object