In my earlier post I have provided sample code to set different data type fields using late bound in MS CRM 2011. In this post I am going to how can we fetch value from different data type fields.
Entity _Account = service.Retrieve(“account”, new Guid(“XXXXX”), new ColumnSet(new string[] { “name”, “accountcategorycode”, “new_collectiondate”, “creditlimit”, “parentaccountid”, “new_executivecommission”, “new_isbilled” }));
//To fetch string value
string Name = _Account[“name”].ToString();
//To fetch optionset selected value
int OptionSetValue = ((OptionSetValue)_Account[“accountcategorycode”]).Value;
//To fetch date time field value
DateTime CollectionDate = ((DateTime)_Account[“new_collectiondate”]).Date;
//To fetch money field value
decimal Creditlimit = ((Money)_Account[“creditlimit”]).Value;
//To fetch decimal field value
decimal Executivecommission = (decimal)_Account[“new_executivecommission”];
//To fetch lockup field
Guid ParentAccountID = ((EntityReference)_Account[“parentaccountid”]).Id;
//To fetch Boolean field
Boolean IsBilled=(Boolean)_Account[“new_isbilled”];
As for me
var fieldvalue = _Account.GetAttributeValue(“fieldname”);
looks more pretty.
As for me
var fieldvalue = _Account.GetAttributeValue<Type>(“fieldname”);
looks more pretty.