Few year back we wrote a quick blog post for working with Dynamics CRM 2011 data types which helped many developers and today we are sharing updated sample code to work with Dynamics 365/CRM data types. If you are looking for late bound sample code for setting different Dynamics 365/CRM data types, you can refer following sample code, We have created a demo custom entity with all possible data types:
Entity demoEntity = new Entity("him_demo"); //string or multiple demoEntity["him_name"] = "Dynamics 365 Data Type Demo"; //currency demoEntity["him_democost"] = new Money(50000); //datetime demoEntity["him_demodate"] = new DateTime(2017, 10, 16); //decimal demoEntity["him_demodiscount"] = 55.6; //Option set value demoEntity["him_demotypes"] = new OptionSetValue(100000000); //available option set value //Two Optionset demoEntity["him_demorequired"] = true; //Whone number demoEntity["him_democount"] = 20; //lookup or customer type demoEntity["him_democontact"] =new EntityReference("contact", new Guid("GUID of contact"));
Hope it will help new developers !!!
Pingback: Working with Dynamics 365 Data Types- Sample Code - Microsoft Dynamics CRM Community