Posts

Showing posts from September, 2014

Setting value in ms crm

I have seen many question in MS CRM Development where Consultant asking for MS CRM 2011 data type related question, like how to set lookup field, how to set/retrieve optionset value. so I thought to write code to show how we can set different data type field in MS CRM 2011. Below is the example to create account using late bound Entity _Account = new Entity(); _Account.LogicalName = “account”; //setting text field _Account.Attributes.Add(“name”, “Myaccount123″); //setting optionset field _Account.Attributes.Add(“accountcategorycode”, new OptionSetValue(2)); //setting datetime field _Account.Attributes.Add(“new_collectiondate”, new DateTime(2012, 3, 25)); //setting currency field _Account.Attributes.Add(“creditlimit”, new Money(300)); //setting lookup _Account.Attributes.Add(“parentaccountid”, new EntityReference(“account”, new Guid(“XXX-XXX……..”))); //setting decimal _Account.Attributes.Add(“new_executivecommission”, new Decimal(55.5)); //setting boolean _Acco

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"]
MS CRM 2011 Entity Images PreEntityImages : (Gets the properties of the primary entity before the core platform operation has begins) PreEntityImages used to capture the data when the form loads. That is the data which is present by default when the form loads.  The syntax for using the PreEntityImages in CRM 2011 is changed as compared to CRM 4.0. Note:The PreEntityImages cannot be registered for “create” operation. Syntax Used in CRM 2011 : ======================= Suppose you registered the Plugin and added a Image with name “PreImage ” public EntityImageCollection PreEntityImages { get;} PostEntityImages : (Gets the properties of the primary entity after the core platform operation has been completed. ) The PostEntityImages contains the attributes value which are finally changed. We can capture the changed data before the database operation takes place. And can do any kind of validation based on the changed data. Note: PostEntityImages can only be registered  for