Michael Philip's Blog

Writing about MS Tech with strong focus on Azure & CRM

Retrieve Fields Values Using Late Bound In Microsoft Dynamics CRM 2011

2 Comments

The following code shows how to retrieve the value of many fields of different types in Microsoft Dynamics CRM 2011, lets apply this behavior on a record of the “Account” Entity.

Code:

//Get the record of the “Account” entity.
Entity _Account = OrganizationService.Retrieve(“account”, new Guid(“recordguid”), new ColumnSet(){AllColumns=true});

//To get string value
string Name = _Account[“name”].ToString();

//To get Option Set selected value

int OptionSetValue = ((OptionSetValue)_Account[“accountcategorycode”]).Value;

//To get  Option Set selected text

String  OptionSetTest = ((OptionSetValue)_Account.FormattedValue[“accountcategorycode”]).Value;

//To get  date time field value

DateTime CollectionDate = ((DateTime)_Account[“new_collectiondate”]).Date;

//To get  money field value

decimal Creditlimit = ((Money)_Account[“creditlimit”]).Value;

//To fetch decimal field value

decimal Executivecommission = (decimal)_Account[“new_executivecommission”];

Advertisements

2 thoughts on “Retrieve Fields Values Using Late Bound In Microsoft Dynamics CRM 2011

  1. The option set formatted value line should be like this:
    String OptionSetTest = _Account.FormattedValue[“accountcategorycode”];

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s