Get next case functionality for Dynamics CRM

Dynamics CRM offers sophisticated tools for working with cases and service queues, but sometimes users just want a quick and simple way to get the next case to work. In today's post, I'll share an easy way to implement this functionality in your Dynamics CRM organization.

There are three components to my approach:

  1. First, there is a custom workflow activity that searches a queue for unassigned cases and assigns the one that entered the queue earliest to a user. This activity returns the assigned case id and case number as output parameters.
  2. Second, there is a CRM action that that acts as a wrapper for the custom workflow activity.
  3. Finally, there is a web resource that displays a button to call the CRM action and generate a link to the assigned case (or a message if there are no cases in the queue to assign).

Let's look at each of these pieces in more detail. If you'd rather get right to the code, scroll to the bottom of this post for a link.

The custom workflow activity

The custom workflow activity has the following parameters:

  1. Queue - input - Reference to the queue that contains the case
  2. User - input - Reference to the user who will be assigned the case
  3. Assign - input - Flag for whether to assign the case or just return the case details
  4. Remove from queue - input - Flag for whether to completely remove the case from the queue when it is assigned
  5. Case id - output - Case GUID as a string (string because it makes working with non-existing cases easier in the custom action)
  6. Case number - output - Case ticket number value
  7. Case found - output - Flag for whether a case was found
  8. Case title - output - Case title value

The activity then executes a FetchXML query to retrieve unassigned cases in ascending order of the date they entered the queue. If the "assign" flag is set to true, the first case is assigned to the user, and then the details are returned as output parameters. If the flag is set to false, the case details are returned as output parameters, but the case is not updated.

The CRM action

The action is the simplest part of the solution. It just takes input parameters to pass to the custom activity and then returns the output parameters.

The get next process

The web resource

Finally the web resource uses JavaScript to call the action and display a link to the assigned case. If no "next" case can be found, then a message is displayed to the user. In my solution, the queue id and assign/remove from queue flags are supplied as encoded query string parameters.

The image below shows the output after the get next button is clicked:
The get next button

The web resource approach allows you to embed the button in a dashboard or CRM form through an iframe, but you could also trigger the action from a ribbon button using similar JavaScript.

The code

You can download all the custom code and a CRM solution extract from my Crm-Sample-Code repository on GitHub. Happy case management!

comments powered by Disqus