I have seen many question in MS CRM Development where Consultant 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);
service.Create(_Account);
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);
service.Create(_Account);
No comments:
Post a Comment