Retrieve MS CRM fields using late bound

In this post I am going to Show 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"];

Comments

Popular posts from this blog

Workflow Activity Input and Output Parameters and Data Types in MS CRM 2013/15/16

Get Workflow Guid in Javascript using OData query

Convert Plugin to Sandbox mode,