Retrieve MS CRM fields using late bound

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”];

Enjoy !!!


1 Comment

Filed under MS CRM 2011

One response to “Retrieve MS CRM fields using late bound

  1. As for me
    var fieldvalue = _Account.GetAttributeValue<Type>(“fieldname”);
    looks more pretty.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s