Dynamics 365’s Queues to Control the Routing of Emails

Introduction

Customer support representatives must handle numerous amounts of emails as part of their daily routine. This poses a lot of challenges for them as handling incoming and outgoing emails efficiently can become taxing. The chances of human error also tend to increase when a representative must handle a vast amount of data in a short period. To facilitate this entire process customer support representatives often make use of Dynamics 365’s queues to control the routing of emails, minimize human error and ensure that the emails are handled promptly.

What Are Queues?

Queues are essentially a layer on top of shared mailboxes in Exchange. They pull incoming emails into Dynamics 365 and then route the mails to different teams. Queues can be a very useful tool for customer service representatives as it allows users to view all incoming emails in one place. Furthermore, it can be customized by administrators to assign items like emails or case records to different people and teams.

Problem Scenario

A common use case for handling email correspondence is to receive emails in Dynamics 365 via these queues for incoming emails, and then actioning them as cases.  This workflow can be supported out of the box, but the outgoing correspondence is not quite as straightforward as the incoming emails.  Emails sent from a case in Dynamics can be received by the customer with the personal email address of the representative who is actioning the case by default.  This poses problems for most organizations:

Elevating Your Dynamics 365 Experience

Elevate your Dynamics 365 experience with AlphaBOLD’s expert services. Whether it's customization, integration, or training, our team is here to ensure you get the most out of Dynamics 365.

Request a Demo

Solution

To resolve this, we need to change the default behavior to ensure that emails originating in Dynamics are sent to customers in a queue rather than directly from a given user.  In this blog, we will be looking at two methods that will help solve this problem for users!

Before we move on, here are some prerequisites that you need to be aware of!

  • A queue for the customer service team has already been created, and the mailbox includes a valid email address that has already been enabled for your organization. In our example, we will be using this queue:
this image shows the Customer JavaScript - Dynamics 365's Queues
  • You need to have a basic understanding of how to access and modify configuration settings like form properties.

With that out of the way, let’s dive into the first of our approaches, a real-time workflow.

Read more about Streamlining Your Workflow: Automation Features Of Dynamics 365

A Real-Time Workflow:

Create a new workflow with the following settings:

  • Category: Workflow
  • Entity: Email
  • Run this workflow in the background unchecked
    • This is critical because we want to make sure that the From address is changed before the email is sent.
this image shows the create process - Dynamics 365’s Queues

Configure the workflow’s trigger behavior:

  • Set an appropriate Scope. I want this workflow to run for anyone in the organization so I have chosen Organization, but Business Unit or Parent: Child Business Unit is also valid if this behavior should be more specific.
  • Record is created checked
  • Record fields change checked
    • Click the Select button and select Regarding. This will allow the workflow to run if a saved email gets assigned to a case, in addition to when it’s created.
this image shows the workflow trigger behavior - Dynamics 365's Queues

Configure the workflow’s logic as per the following:

  • This will check to confirm that the email is open, outgoing, and regarding a case. Then, update the email form.
this image shows the workflow logic- Dynamics 365's Queues

Click on the Set Properties button in the Update: Email step, and enter the queue in the From field lookup:

this image shows the Set Properties button- Dynamics 365's Queues

Save and publish the workflow. Now, when users will create email records from the Timeline on a case, the email will automatically be set to come from Customer Service when:

this image shows the Customer Service hub- Dynamics 365's Queues

The workflow strategy should be appropriate for most use cases, but there are some potential scenarios in which JavaScript is the preferable option.  Here is the process for building the same functionality we saw with the workflow, but with JavaScript instead:

Custom JavaScript:

Get the queue name and GUID for the queue you’d like added in the From:

  • To get the GUID, open the queue record and click on the Pop-out this form button at the upper right:
this image shows the Custom JavaScript

Copy the queue & re Pass execution context:

  • ID value from the URL and store it for later:
this image shows the Pass execution context

Create a new web resource with the following settings:

  • Type: Script (Jscript)
this image shows the web resource

Copy the following script into a text editor like Notepad or Visual Studio Code:

function setFromAddressToQueue (executionContext) {  const formContext = executionContext.getFormContext();  const regardingObject = formContext.getAttribute(“regardingobjectid”).getValue();  const emailStatus = formContext.getAttribute(“statecode”).getValue();  const emailDirection = formContext.getAttribute(“directioncode”).getValue();   // if email is regarding a case  if (regardingObject && regardingObject[0].entityType === “incident”) {    // if email status is open and direction is outgoing    if (emailStatus === 0 && emailDirection === true) {      // build the lookup object      const queueLookup = [        {          id: “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”,          name: “Queue Name”,          entityType: “queue”        }      ];       // set the from field to the appropriate queue      formContext.getAttribute(“from”).setValue(queueLookup);    }  } }

Modify the script, pasting the GUID and queue name into to the queueLookup object:

this image shows the queueLookup object

Copy this script and paste it into the text editor for the new web resource:

this image shows the new web resource
  • Save and publish the web resource.
  • Navigate to the main email form being used in your organization.
    • This form will be called “Email for interactive experience” by default if using Unified Interface, as of version 9.1.
this image shows the Unified Interface

Open the form properties window and add the web resource as a form library:

this image shows the properties window

Add the function to the following areas:

  • Control: Form | Event: OnLoad
    • Make sure the Pass execution context as the first parameter is checked. The script will not work without this selected, as it needs the execution context to get the required data.
  • Control: Regarding | Event: OnChange
    • Make sure the Pass execution context as the first parameter is checked. The script will not work without this selected, as it needs the execution context to get the required data.
this image shows the Event OnChange
this image shows the handler properties

Save and publish the email form. Now, when users create email records from the Timeline on a case, the email will automatically be set to come from Customer Service immediately when the email record is opened, even before saving:

this image shows the email Customer Service

As with most Dynamics modifications, the tradeoff between the workflow approach and custom JavaScript is that the former will be more robust due to using out of the box configurations and the latter will be more customizable.  In this particular example, the workflow will not change the From address when the email form is loaded, only when the email is saved or sent. However, the JavaScript will handle this on load, which can make it more intuitive for users. Regardless of which method is used, the result is the same.

Transform Your Operations with AlphaBOLD’s Dynamics 365 Expertise

Maximize the efficiency and productivity of your business with AlphaBOLD's tailored Dynamics 365 solutions.

Request a Demo

Conclusion

Any outgoing email regarding a case will automatically be sent from the selected queue instead of from the user, reducing the likelihood that a customer will try to reach out to a representative directly rather than moving through the support process as normal.  This logic can also be expanded to use different queues for different purposes: for example, some businesses may want to have emails in different regions sent from different queues. If you have any questions, inputs or insights on this blog, get in touch using the comment box below!

Explore Recent Blog Posts

Infographics show the 2021 MSUS Partner Award winner

Related Posts

Receive Updates on Youtube

2 thoughts on “Dynamics 365’s Queues to Control the Routing of Emails”

  1. Hi Bolden,
    This looks like a good article.
    I tried method 1 to achieve the same requirement.
    It is not working in my case. I am using D365 Online version.
    What might be the problem. Please help me if you can.
    Regards,
    Babu

  2. Hi Babu,

    Thank you for your comment! Are you encountering any client-side errors when email records are saved? Are there any failed process sessions in the workflow’s associated view?

    It’s worth keeping in mind that the workflow approach will not show the queue in the From address until the email record is saved. This is the main advantage of the JavaScript approach versus the real-time workflow, it immediately makes the change visible to users when the email creation process begins.

    Here are a few other things to check:

    • Make sure the workflow is set up in real-time. This process will not work consistently if the workflow is asynchronous (running in the background), because the email record will likely send before the From address is modified.

    • With the logic specified in the blog, this process requires a user to create the email from the Timeline of an existing Case record. If the email is created from anywhere else in the system, including the New button in the top navigation bar, the behavior will not trigger.

Comments are closed.