Quick Create Contact from the Phone Call Form

Here’s a solution I’ve mocked up to speed up call handling times in a particular Call Centre scenario. 

Here we have Microsoft Dynamics CRM 2011 deployed into a Call Centre where our CSR’s are tasked with processing inbound calls.   The CRM system has been integrated to the telephony system such that when the caller can be matched to a CRM Contact record that Contact record pops for the user.  

But when the caller can’t be matched we want the CRM Phone Call form to pop for the user instead and we want to give the user a minimal-click solution that allows them to both record the Phone Call and the Contact.   Here’s what I came up with:


The telephony integration takes care of popping this form and provides us with the phone number of the caller.  It also populates the subject field for us as well.

If the CSR’s conversation with the caller indicates they should be in CRM (suggesting that the number they have called in from is new/different) then the CSR can use the out-of-the-box Sender field to search for the caller.

If the caller is new to us though the user can simply complete these steps to quickly create the Contact and link the Phone Call to the new Contact record:

1. The CSR clicks into the Title field in the Quick Create New Contact section of the form and populates:


Note: As soon as the CSR populates one of the fields in this section all the fields in the section become mandatory.

2. The CSR tabs out of the first field and then populates the second, and then the third:


3. The user tabs out of the Last Name field and custom code (jscript) is triggered. 

The code detects that all 3 mandatory fields have now been populated.  The jscript collects the field values from the form and then executes a REST call to create a new Contact based on those values.  On success, the code then updates the Sender field to reflect the Contact that was created and then disables the Quick Create fields:


For the user, the back end processing is invisible.  They simply followed an intuitive process. 

A little bit of jscript used in an supported (upgrade friendly) manner has allowed us to streamline the process by removing 6 clicks and one form load.   In a Call Centre environment this is gold.  

Here’s the jscript behind this.  The OnLoad function needs to be attached to the form’s OnLoad event.  The NewContact function needs to be attached to the OnChange event of the Title, First Name and Last Name fields.  The CreateContact function does the heavy lifting.

// Set lookup value of a field 
function SetLookupValue(fieldName, id, name, entityType) { 
    if (fieldName != null) { 
        var lookupValue = new Array(); 
        lookupValue[0] = new Object(); 
        lookupValue[0].id = id; 
        lookupValue[0].name = name; 
        lookupValue[0].entityType = entityType; 

function DisableFields() { 

function MakeFieldsMandatory() { 

function MakeFieldsNonMandatory() { 

function OnLoad() { 
    if (Xrm.Page.ui.getFormType() == 1) { 
        Xrm.Page.getAttribute("subject").setValue("Inbound phone call"); 
        Xrm.Page.getAttribute("phonenumber").setValue("+65 9784 5862"); 
    else if (Xrm.Page.ui.getFormType() != 1) { 

function NewContact() { 
    if (Xrm.Page.getAttribute("new_title").getValue() == null && 
            Xrm.Page.getAttribute("new_firstname").getValue() == null && 
            Xrm.Page.getAttribute("new_lastname").getValue() == null && 
            Xrm.Page.getAttribute("phonenumber").getValue() == null) { 
    else if (Xrm.Page.getAttribute("new_title").getValue() != null && 
                Xrm.Page.getAttribute("new_firstname").getValue() != null && 
                Xrm.Page.getAttribute("new_lastname").getValue() != null && 
                Xrm.Page.getAttribute("phonenumber").getValue() != null && 
                Xrm.Page.data.entity.attributes.get("from").getValue() == null) { 
    else { 

function CreateContact() { 
    // Get the CRM URL 
    var serverUrl = Xrm.Page.context.getServerUrl(); 

    // Cater for URL differences between on premise and online 
    if (serverUrl.match(/\/$/)) { 
        serverUrl = serverUrl.substring(0, serverUrl.length - 1); 

    // Specify the ODATA end point (this is the same for all CRM 2011 implementations) 
    var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc"; 

    // Specify the ODATA entity collection 
    var ODATA_EntityCollection = "/ContactSet"; 

    // Define an object for the CRM record you want created 
    var CRMObject = new Object(); 

    // Define attribute values for the CRM object 
    CRMObject.FirstName = Xrm.Page.getAttribute("new_firstname").getValue(); 
    CRMObject.LastName = Xrm.Page.getAttribute("new_lastname").getValue(); 
    CRMObject.Salutation = Xrm.Page.getAttribute("new_title").getValue(); 
    CRMObject.Telephone1 = Xrm.Page.getAttribute("phonenumber").getValue(); 

    //Parse the entity object into JSON 
    var jsonEntity = window.JSON.stringify(CRMObject); 

    //Asynchronous AJAX function to Create a CRM record using OData 
        type: "POST", 
        contentType: "application/json; charset=utf-8", 
        datatype: "json", 
        url: serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection, 
        data: jsonEntity, 
        beforeSend: function (XMLHttpRequest) { 
            //Specifying this header ensures that the results will be returned as JSON.      
            XMLHttpRequest.setRequestHeader("Accept", "application/json"); 
        success: function (data, textStatus, XmlHttpRequest) { 
            //This function will trigger asynchronously if the Retrieve was successful 
            //alert("ajax call successful"); 
            var NewCRMRecordCreated = data["d"]; 
            var FullName = Xrm.Page.getAttribute("new_firstname").getValue() + " " + Xrm.Page.getAttribute("new_lastname").getValue(); 
            SetLookupValue("from", NewCRMRecordCreated.ContactId, FullName, "contact"); 
        error: function (XmlHttpRequest, textStatus, errorThrown) { 
            //This function will trigger asynchronously if the Retrieve returned an error 
            alert("ajax call failed"); 

You will need to upload the json and jquery libraries as web resources and reference in the On Load event along with the OnLoad function:


A CRM solution file containing these web resources and the changes to the Phone Call form are available for download here.


4 thoughts on “Quick Create Contact from the Phone Call Form

  1. Pingback: Quick Create Contact from the CRM Case Form « Gareth Tucker's Microsoft CRM Blog

  2. puneet joshi


    I have a business requirement where I have to copy record from Entity A to Entity B on Click of a Ribbon Button.

    On Entity A’s Form, i have created a Ribbon button called “Copy Record”, Because i was not able to trigger Plug-in from Ribbon button, i have used a hidden Boolean field (Yes/No) in the Entity A’s Form and on click on that Ribbon Button i am updating the Boolean field’s Value from NO to Yes. Then i am trying to trigger a plug-in which will create a record in the Update Message of Entity A. I Could not figure out where and why it is failing. I have a deadline so i was looking into other options, i visited your post and seems like it can help.

    I could have used WF’s to do it but the only challenge is I can copy the Option Sets using Work Flow. Other than that everything is getting copy over. I am sure you have see this post ages back. http://blogs.msdn.com/b/crm/archive/2008/06/13/use-workflow-to-configure-business-data-auditing-in-microsoft-dynamics-crm-4-0.aspx

    Please direct me how to leverage your above mentioned code to copy record from one entity to another. Entity B’s fields are same as Entity A (Similar DataType, Similar Structure).
    Also i have 100+ record in Entity A’s form to copy over to Entity B. Will it possible to copy so many fields.

    Your help will be much appreciated.


  3. Bill Harts


    Thanks very much for posting this. I have one question: how do you retrieve meaningful error information if the AJAX call fails? I’m displaying the contents of textStatus and errorThrown in the error function, but just get the text “error”.

    Thanks in advance!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s