Working with MS CRM 2011 data types

I have seen many question in MS CRM Development where developers asking for MS CRM 2011 data type related question, like how to set lookup field, how to set/retrieve optionset value. so I thought to write code to show how we can set different data type field in MS CRM 2011.

Below is the example to create account using late bound

Entity _Account = new Entity();
_Account.LogicalName = “account”;
//setting text field
_Account.Attributes.Add(“name”, “Myaccount123”);

//setting optionset field
_Account.Attributes.Add(“accountcategorycode”, new OptionSetValue(2));

//setting datetime field
_Account.Attributes.Add(“new_collectiondate”, new DateTime(2012, 3, 25));

//setting currency field
_Account.Attributes.Add(“creditlimit”, new Money(300));

//setting lookup
_Account.Attributes.Add(“parentaccountid”, new EntityReference(“account”, new Guid(“XXX-XXX……..”)));

//setting decimal
_Account.Attributes.Add(“new_executivecommission”, new Decimal(55.5));

//setting boolean
_Account.Attributes.Add(“new_isbilled”, true);


we should get new account created like below

In next post I will show how to retrieve different data types fields using server side code.

Enjoy !!!

3 thoughts on “Working with MS CRM 2011 data types

  1. Pingback: Retrieve MS CRM datatype fields using late bound « Mahender Pal

  2. Pingback: Retrieve MS CRM fields using late bound - Mahender Pal - CRM Technical Blogs - Microsoft Dynamics Community

  3. Pingback: Working with Dynamics 365 Data Types- Sample Code | HIMBAP

Leave a Reply

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