web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

Community site session details

Community site session details

Session Id :

Existing customer assignment on new inbound conversation

Fameeda Yaseen Profile Picture Fameeda Yaseen 451
This solution demonstrates how Dynamics 365 Contact Center for Customer Service can automatically identify and assign existing customer records to new inbound conversations using JavaScript and the CE Web API. Agents can see customer information immediately in the conversation pop-up, improving efficiency and response times.
Architecture

Dataflow
  1. A customer places an inbound call to the contact center.
  2. Dynamics 365 Contact Center generates a new conversation and displays the active conversation pop-up.
  3. A JavaScript function executes to fetch the conversation ID and check if inbound call phone number is populated.
  4. The JavaScript code extracts the phone number from the conversation.
  5. Using the Dynamics 365 CE Web API, the system queries Dataverse for an existing customers matching the phone number.
  6. If a matching customer exists, it is automatically linked to the conversation.
  7. The agent interface updates, and customer details are displayed in the conversation pop-up.
Components
  • Dynamics 365 Contact Center for Customer Service
    Handles inbound call routing, live conversations, and agent interface.
  • Dataverse
    Stores contact and customer data as well as live work items.
  • Dynamics 365 CE Web API
    Queries existing customer records based on the phone number.
  • JavaScript client-side logic
    Fetches conversation ID, retrieves customer data, and links records to conversations.
Scenario details
Inbound calls to contact centers often show only the caller's phone number in the agent interface. Without automatic linking, agents must manually search for the customer, slowing down service and similarly, increase the steps for the agent, search the customer and link to the conversation. This solution enables real-time detection of existing customers using the phone number as the key, automatically linking the customer record to the conversation.
Potential use cases
  • Retail: Quickly display returning customer details and purchase history.
  • Finance: Show account information immediately for faster call resolution.
  • Healthcare: Identify patients efficiently for better service.
  • Telecommunications: Surface subscriber information instantly to agents.
Applicable across industries where inbound call handling and rapid customer identification are critical.
Sample implementation
Git Repo Location: https://github.com/fahmeedayaseen86-png/ContactCenterSolutionIdeas.git
//Automatically identify and link existing Dynamics 365 customer records to C Contact Center inbound conversations using JavaScript and CE Web API
//Register method against onload event of conversation record.
function SetContact(executionContext) {
    try {
        window.top.Microsoft.Omnichannel.getConversationId().then(
 
            function success(ConversationId) {
 
                if (ConversationId != null) {
                    debugger;
                    checkIfContactAlreadyLinked(executionContext, ConversationId);
                }
            },
            function error(err) {
                debugger;
                console.log("Error in Getting Conversation ID. " + err);
            }
        );
    }
    catch (excep) {
        console.log(excep)
    }
}
 
 
function wait(ms) {
 
    var start = new Date().getTime();
 
    var end = start;
 
    while (end < start + ms) {
 
        end = new Date().getTime();
 
    }
 
    Xrm.Utility.closeProgressIndicator();
 
}
 
 
 //Checked is contact is already exist.
 
function checkIfContactAlreadyLinked(executionContext, ConversationId) {
 
    Xrm.WebApi.online.retrieveMultipleRecords("msdyn_ocliveworkitem", "?$select=_msdyn_customer_value&$filter=msdyn_ocliveworkitemid eq '" + ConversationId + "'").then(
 
        function success(data) {
            debugger;
            if ((data !== null) && (data.entities !== null) && (data.entities.length > 0) && data.entities[0]._msdyn_customer_value == null) {
 
                createContactLinkContact(ConversationId, executionContext);
 
            }
 
            else {
                debugger;
                console.log("Omnichannel: Contact Already Created and Linked ",);
 
            }
            debugger;
            console.log("2 GUID: ",);
 
        }
 
    );
 
}
 
 
//Link customer with the conversation 
function createContactLinkContact(ConversationId, executionContext) {
    debugger;
 
    var phone;
 
    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Utility.getGlobalContext().getClientUrl() + "/api/data/v9.2/msdyn_ocliveworkitems(" + ConversationId + ")?$select=subject", false);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Prefer", "odata.include-annotations=*");
    req.send();
    if (req.status === 200) {
        var result = JSON.parse(req.response);
        console.log(result);
        // Columns
        var activityid = result["activityid"]; // Guid
        var subject = result["subject"]; // Text
        var _phone = subject.split(':');
        // phone = _phone[0];
        phone = _phone[0].replace('+', '');
        GetCustomerDetails(executionContext, ConversationId, phone);
    }
    else {
        console.log(req.responseText);
    }
}
 
 //get customer details in the base of phone number
function GetCustomerDetails(executionContext, conversationId, PhoneNumber) {
    debugger;
 
    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Utility.getGlobalContext().getClientUrl() + "/api/data/v9.2/contacts?$select=firstname,fullname,lastname&$filter=(contains(telephone1,'" + PhoneNumber + "') or contains(address1_telephone1,'" + PhoneNumber + "'))", false);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Prefer", "odata.include-annotations=*,odata.maxpagesize=1");
    req.send();
 
    if (req.status === 200) {
        var result = JSON.parse(req.response);
 
        if (result.value && result.value.length > 0) {  // Ensure data exists
            var contact = result.value[0]; // Get first contact
            var contactid = contact.contactid; // Guid
            var fullname = contact.fullname; // Text
 
            Microsoft.Omnichannel.linkToConversation("contact", contactid, conversationId).then((response) => {
                // Refreshing the tab UI  
                Microsoft.Apm.getFocusedSession().getFocusedTab().refresh();
            }, (error) => {
                console.log(error);
            });
        } else {
            console.log("No matching contact found.");
        }
    } else {
        console.log(req.responseText);
    }
}


Contributors
This article is maintained by Microsoft. It was originally written by the following contributors.
Principal authors:
  • Fahmeeda Yaseen | FastTrack Solution Architect

Next steps

Related resources

code snippet widget

Comments