lead qualification skip opportunity

On a recent customer upgrade from CRM 2011 to CRM 2016 Dynamics 365 we reviewed the current way of working and how this would be affected by the upgrade which spans quite a few versions.

Since CRM 2013 the lead conversion process changed. The selection screen that asks which records you want to create disappeared and a more business process driven approach has come instead. This gives a smooth user experience if you use the end-to-end process including opportunities.
This wasn’t the case in the scenario of our customer. They have a B2C focused business where every lead is converted into a contact (and synced with a backend system). Occasional accounts should be created, but during the process the contact is key. So a BPF is overkill in this scenario.

Since there is more than one way leading to Rome.

We choose to add a plugin on the lead qualification message to prevent the creation of the opportunity.
Plugin registration Info:

Message: QualifyLead
Entity: Lead
Stage: Pre-validation

And here is the custom code doing the magic, it exists actually of only one line:

context.InputParameters["CreateOpportunity"] = false; // Prevent opportunity from being created

And Done! Mmmm … almost, because when you click the qualify button it seems nothing is happening.
After a manual refresh of the form, you will see that the lead is qualified and no opportunity is created.

Well there goes our user experience …

So how do we fix this? Ok, let’s start by adding an on save handler that will in case of lead qualification (savemode 16), wait for 1,5 seconds before refreshing the formdata and take the “parentcontactid” to open the newly created contact.

function RefreshOnQualify(eventContext) {
    if (eventContext != null && eventContext.getEventArgs() != null) {
        if (eventContext.getEventArgs().getSaveMode() == 16) {
            setTimeout(function () {
                Xrm.Page.data.refresh(false).then(function () {
                    var contactId = Xrm.Page.getAttribute("parentcontactid").getValue();
                    if (contactId != null && contactId.length > 0) {
                        Xrm.Utility.openEntityForm(contactId[0].entityType, contactId[0].id)
                    }
                }, function (error) { console.log(error) });;
            }, 1500);
        }
    }
}

In order for this to work, make sure that the “parentcontactid” lookup is available on the form.
This field is automatically updated with the contact ID by the out of the box process. In addition, the same applies for the “parentaccountid”.

As a result we obtain a fluent user experience that automatically opens the new contact on qualification of a lead.