Retrieve Fields Values Using Late Bound In CRM

The following code shows how to retrieve the value of many fields of different types in CRM , let's 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"];

2 thoughts on “Retrieve Fields Values Using Late Bound In CRM”

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

Leave a Reply

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