Posts

Showing posts from 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
Workflow solution creation , registration and usage in CRM2011 In this blog I would like to explain some practical steps about the Workflow lifecycle in CRM 2011. The steps includes  1. Creation of the workflow solution ( C# solution ) and generation of the assembly  2. Registering the workflow assembly for CRM usage 3. Using the workflow assembly in CRM  1. Creation of the workflow solution and generation of the assembly  The workflow can be defined as group of activities that performs the required process.+ a) Creating the activities of the Workflow steps in the C# solution   Workflow activities are defined in the System.Activities.dll of .NETFramework, so we need to add this dll to the workflow solution. Define the Class :  The workflow activities that are used in CRM are derived from the "CodeActivity" base class.  so define the workflow activity class derived from the "CodeActivity" class.      eg : public class Sampleworkflow : CodeActivity {}   O
Associate two records using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Activities; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Workflow; using Microsoft.Xrm.Sdk.Messages; using Microsoft.Xrm.Sdk.Query; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk.Metadata; namespace AssociatedLeadEmail_WF {     public class AssociatedLeadEmail_WF : CodeActivity     {         #region Set the input mandatory parameters.         //Input Value of Associated Lead Record         [RequiredArgument]         [Input("Email Send")]         [ReferenceTarget("cdi_emailsend")]         public InArgument<EntityReference> EmailSend { get; set; }         [RequiredArgument]         [Input("Lead")]         [ReferenceTarget("lead")]         public InArgument<EntityReference> Lead { get; set; }         [Output("Success")]         public OutArgument<bool>
Send Template Email The Send Template Email custom workflow activity will search for Template Records where the Lead Source and Lead Sub-Source are match the Source and Sub-Source from the designated lead, or are null. Using the email template specified on the Template Record, the custom workflow activity will create an email from the template and send it to the lead using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Activities; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Workflow; using Microsoft.Xrm.Sdk.Messages; using Microsoft.Xrm.Sdk.Query; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk.Metadata; namespace LeadTemplate_WF {     public class LeadTemplate_WF : CodeActivity     {         #region Set the input mandatory parameters.         //Input Value of Template Record         [RequiredArgument]         [Input("new_leadorigin")]         [ReferenceTarget("sbi_leadorigin")]
Ribbon and UI Customizations Email Template Selector On the form ribbon of the Template Record add a flyout to display a list of Email Templates for leads. On click of a button in the flyout, set the Template field to the id of the specified Email Template. The flyout should be enabled only for existing, editable records. Code: /************************************************ populateArticles - function to populate a button on the ribbon with the available disclaimers Policy is 1 ************************************************/ function PopulateArticles1(CommandProperties) {     var serverUrl = Xrm.Page.context.getClientUrl();     var requestUrl = serverUrl + "/xrmservices/2011/OrganizationData.svc/cdi_emailtemplateSet?$select=cdi_emailtemplateId,cdi_name&$filter=statecode/Value eq 0";          $.ajax({         type: "GET",         contentType: "application/json; charset=utf-8",         datatype: "json&qu
Useful Javascript which is used Frequently in MS CRM. 1.  Get the GUID value of a lookup field: Note: this example reads and pops the GUID of the primary contact on the Account form function AlertGUID() {     var primaryContactGUID = Xrm.Page.data.entity.attributes.get("primarycontactid").getValue()[0].id;     alert(primaryContactGUID); } 2. Get the Text value of a lookup field: Note: this example reads and pops the name of the primary contact on the Account form function AlertText() {     var primaryContactName = Xrm.Page.data.entity.attributes.get("primarycontactid").getValue()[0].name;     alert(primaryContactName); } 3.  Get the value of a text field: Note: this example reads and pops the value of the Main Phone (telephone1) field on the Account form function AlertTextField() {     var MainPhone = Xrm.Page.data.entity.attributes.get("telephone1").getValue();     alert(MainPhone); } 4.  Get the database v