Friday, July 15, 2016

Improving MS CRM Performance

Performance on MS CRM is always a crucial thing and we may follow different ways to achieve the performance thing. Below is the one more approach we can improve the performance bit more.
In IIS setting of a website where MS CRM is hosted, there we can change the Output Cache property. By changing this property to true, initially any entity record load may take bit time; later on it will open the records in much lesser time. This is quite a good approach to improve the performance.
Below screenshot explains where to change the output Cache settings

Open IIS, click on Microsoft Dynamics CRM site-> On Right side Panel click on Feature View-> Configuration Editor









































(source of below description: MSDN)
What is omitVaryStart:
Gets or sets a value indicating whether the vary header is enabled.


true if the vary header is enabled; otherwise, false. The default is false.

The vary header indicates the request-header fields that the server uses to determine which of multiple cached responses are sent in response to a client request. The default for the OmitVaryStar property is false. By default, ASP.NET sends the vary header in all POST requests, as well as in all GET-request query strings. If the OmitVaryStar is true, ASP.NET omits the vary header when returning the response for cached pages, provided that the GET request to a response is cached with no VaryByCustom property and thePOST request to a response is cached with no VaryByParam property and no VaryByCustom property.

Upsert in MS Dynamics CRM

If we want to update a record in any entity, we should require GUID. If we know the GUID, we can do it easily, if not, we should retrieve the GUID of that record first, then we can update the record. Here, two database calls (Retrieve and Update) we are making which impacts performance of an application.


In these scenarios, Upsert will be very useful. Upsert request will check in database whether record exists in database, if exists it will update the record or else it will create the record.






So, how do we know that whether Upsert create or update record in each call?


This information we can get from UpsertResponse which contains a Boolean property RecordCreated. If RecordCreated contains “true” it indicates Upsert created the record else updated the record.


Sample Code:

               Entity testEntity = new Entity("new_test");
                testEntity["new_test1"] = "test1";
                testEntity["new_test2"] = "test2";
                testEntity["new_test3"] = "test3";

                UpsertRequest request = new UpsertRequest()
                {
                    Target = testEntity
                };
                try
                {
                    UpsertResponse response = (UpsertResponse)_serviceProxy.Execute(request);
                }
                catch (Exception ex)
                {
                  }


Note: For Microsoft Dynamics CRM Online organizations, this feature is available only if your organization has updated to Dynamics CRM Online 2015 Update 1. This feature is not available for Dynamics CRM (on-premises).

Monday, June 20, 2016

MS Dynamics CRM Plug-ins Exception Handling

Its always have Exception blocks as well as finally block to handle all Exception in your custom Plug-ins. Here is basic snap shot.

MS Dynamics CRM Impersonate a user

Impersonation is used to execute business logic (code) on behalf of another Microsoft Dynamics CRM user to provide a desired feature or service using the appropriate role and object-based security of that impersonated user.

Impersonation involves two different user accounts: one user account (A) is used when executing code to perform some task on behalf of another user (B).

To impersonate a user, set the CallerId property on an instance of OrganizationServiceProxy before calling the service’s Web methods.

1) In General Console Application way




2) with in Plugin or Custom work flow




MS CRM Plugins- When to use Entity/EntityReference

For create and Update we use Entity and for Delete it is EntityReference for checking Target.



For other messages we have to use mostly Entity but we need to think where to use EntityReference. For Associate/Disassociate we have to use EntityReference as well. 

Now the Question is What is Target ? Is it all the time used or is any other Properties are available ?

Ans :- Target is a properties for MessageRequest. it is not same for all type of messages.
 For Assign if you have write code , then you can check


For Assign if you have write code , then you can check

Saturday, June 4, 2016

Email signatures in CRM 2016.

CRM2016 Update 1 has introduced email signatures in CRM2016. It is very important if you are using CRM web clients. In the past, CRM users used to copy paste their signatures into CRM emails or used email templates for signatures.
Now you have an option to create one or more personal email signatures.

1. Go to personal options

2. Navigate to the Email Signatures tab and press New.

3. Enter your email signature and press save.

4. You have an option to set the email signature as the default by clicking on the Set as Default button.

Testing the email signatures

Create a new email activity and your default email signature will appear automatically.

There is also a button available ‘Insert Signature’, which adds the signature manually or replaces the default signature. These buttons are highlighted in yellow in the above screenshot.
Note: The embedded images in the email signature will not appear in the email unless they are hosted on the internet.
Now you have email signatures in CRM2016.

How to Qualify Lead without creating Opportunity/Account/Contact in Microsoft Dynamics CRM


How to prevent MS CRM from creating Opportunity/Account/Contact while qualifying a Lead.




A lot of sales teams are frustrated with how lead conversion works in Microsoft Dynamics CRM.  Starting with CRM 2013, whenever a user clicks the “Qualify” button, an Opportunity is always created.  We were hoping to see a fix in CRM 2016 but, sadly, the process still works the same.

How can an organisation reconfigure Microsoft Dynamics CRM to allow sales to qualify a lead without creating an opportunity?

The qualify process built into Microsoft Dynamics CRM assumes that the lead conversion process always ends either in disqualification, or in the creation of an opportunity.  But most businesses have lead conversion scenarios that don’t end in the creation of an opportunity.  Consider the following:

A new contact from an existing account visits the website and completes a contact us form (perhaps requesting a downloadable resource, without any intent to purchase anything at this time).  Sales wants this lead to be visible on the account, so they would like to convert the lead and create a contact, but without creating an opportunity.

Inside Sales qualifies incoming leads, and then passes them along to Field Sales for ongoing contact.  Oftentimes a lead is qualified, but is not yet in the market to make a purchase.  Field Sales still wants to be able to work this prospect, but they don’t work with leads  (only accounts and contacts). They need to convert a lead into an account and contact, but without creating an opportunity.

There are many more scenarios like the two above. 

How can the sales department fix CRM to work the way that they do, instead of being forced to work the way CRM does?

Sometimes what developers does is that they create a custom button on Lead entity ribbon and Write a plugin code using  QualifyLeadRequest Class where they set what to create and what not (among Account/Contact/Opportunity).

Although it serves the purpose,but we have a better solution where we need not to Qualify Lead using different code by calling a plugin from custom button, instead we tell system what to create and what not.
What we need to do is to register a plugin on QualifyLead message on pre-event on lead and set CreateOpportunity/CreateAccount/CreateContact false.


Here what we got is, we need not to hide system Qualify button and neither we need to create other custom button to qualify lead.


Below is the code snippet where i have prevented Lead from creating Opportunity and Account:

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext contextPlugin = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = factory.CreateOrganizationService(contextPlugin.UserId);
            if (contextPlugin.MessageName != "QualifyLead") return;

            OptionSetValue LeadStatecode = new OptionSetValue();
            OptionSetValue LeadStatuscode = new OptionSetValue();
            EntityReference LeadRef = null;
            try
            {
                LeadRef = (EntityReference)contextPlugin.InputParameters["LeadId"];
                Entity Lead = service.Retrieve("lead", LeadRef.Id, new ColumnSet(true));
                if (LeadRef.LogicalName != "lead") { return; }
                LeadStatecode = Lead.GetAttributeValue<OptionSetValue>("statecode");
                LeadStatuscode = Lead.GetAttributeValue<OptionSetValue>("statuscode");
                if (LeadStatecode.Value == 0 && LeadStatuscode.Value == 1)
                {
                    // set to true by default 
                    contextPlugin.InputParameters["CreateOpportunity"] = false;
                    // set to true by default 
                    contextPlugin.InputParameters["CreateAccount"] = false;   
                }
            }
            catch (InvalidPluginExecutionException ex)
            {
                throw new InvalidPluginExecutionException(ex.Message);
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(ex.Message);
            }
        }




If we prevent Account/Contact creation this solution works great,but It have a little issue when we prevent it from creating Opportunity.

In this case there is no opportunity Created to which Lead page can redirect to it keps displaying Lead page.

Now if user clicks Qualify again, system throw error that you can't qualify a already qualified Lead.

But, we have a solution for this as well.

What we can do is write a JavaScript code on Form OnSave event which refresh the form:

var entityname = Xrm.Page.data.entity.getEntityName();
var entityid =Xrm.Page.data.entity.getId();
Xrm.Utility.openEntityForm(entityname,entityid);function refresh(Context) {
    var SaveMode, SaveEventVal;

    // Change the Save Event Value as per required Save Event
    SaveEventVal = 16;

    if (Context != null && Context.getEventArgs() != null) {
        SaveMode = Context.getEventArgs().getSaveMode();

        // 16 will pass on Lead Qualify button click
        if (SaveMode == SaveEventVal) {
            setTimeout(function () {
    var entityname = Xrm.Page.data.entity.getEntityName();
    var entityid =Xrm.Page.data.entity.getId();
    Xrm.Utility.openEntityForm(entityname,entityid);

            }, 1);
        }
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Hope it would be helpful.

Get files of last hour in Azure Data Factory

  Case I have a Data Factory pipeline that should run each hour and collect all new files added to the data lake since the last run. What is...