Adding Items to a Dynamics Queue

Continuing off my post of adding items to a queue programmatically, I wanted to add items to this queue (why else would I be using a queue?).

The code here is relatively simple and boring as I queried for a contact named Andrew, found him and added a new queueitem to the queue.

QueryExpression queryContact = new QueryExpression();
queryContact.EntityName = "contact";
queryContact.ColumnSet = new ColumnSet(true);
queryContact.Criteria.AddCondition("firstname", ConditionOperator.Equal, "Andrew");

EntityCollection entityContacts = _CrmService.RetrieveMultiple(queryContact);
EntityReference contactRef = new EntityReference("contact", entityContacts[0].Id);

Entity q = new Entity("queueitem");
q["queueid"] = new EntityReference("queue", _QueueId);
q["objectid"] = contactRef;
_CrmService.Create(q);

The results were anything but.

The first time I executed this code it worked fine, created a new queueitem record and associated to my man Andrew.

The second time I executed this code, it exploded with the following message (which seems odd for a queue to do).

Picture (Device Independent Bitmap) 1

So then I went to the contact record itself, tried to do this manually, but this time I received no error.  When I checked the queue though, it only had one instance of my queueitem in there.

Still perplexed, I then created a phone call activity, added my contact to it, then added that to the queue (multiple times) and this worked fine (and showed multiple instances in the queue).

Perhaps there is a difference between how Dynamics handles core entity interactions vs activities.  I find it odd that this restriction exists because every record goes into the queue as a unique queue item.  For what I was trying to achieve (logging changes to records, not activities, in the order they were processed) this was not going to work.

Unfortunately, I haven’t found a way around this functionality to disable it.  If anyone knows the reason, I would love to hear the why behind it.

 

Creating a USD Configuration

When getting started with development in the USD (Unified Service Desk), the first thing you have to do is create a configuration profile (otherwise you get an error when you launch the USD).

A configuration profile is what allows you to create many types of USD implementations and associate them to users.  A user can only ever be associated to one profile.

USD_Config

Establishing a base configuration profile is comprised of three parts as indicated below.

usd

The Global Manager is a hosted control which is core of any USD implementation.  The role of this control is load and host all controls related to your configuration, interpreting all controls, rules, toolbar components, scripts and sessions.  A single configuration can only contain one instance of the Global Manager hosted control.

The Connection Manager hosted control type manages connections to the Dynamics365 server, and makes it available to the rest of the agent application.  Theoretically, it would be possible to host an instance of the USD without a Connection Manager, but there would not be significant value to this approach (since it can’t read/write any data to/from Dynamics).

The Panel Layout hosted control defines the arrangement of panels in the Unified Service Desk. Panels can host various controls, and defines the arrangement of various hosted controls of the USD.  There are a number of predefined panel types to support various layout options such as tabbed layout, deck, and stacked layout.  If a Panel Layout type of hosted control is not defined in the application, the default panel layout, Standard Main Panel, is created automatically.

When you have created these three components and associated them to your USD Configuration, you should have a view akin to the following.

USD_Config_2

Best Practices: If I am implementing a custom USD configuration, whether it’s one configuration or many, I will always prepend all related components with a little descriptor (think CRM Publisher) so that I know what belongs to what when I’m associating components.

 

Accessing Dynamics Queues Programmatically

I typically still code in Dynamics using LateBound requests.  There have been a few instances where I have switched to Early Bound but I continue to do this for the following reasons

  1. I don’t like dragging around proxies into my code that can change environment to environment.
  2. When not depending on proxies, I feel have more options to downgrade my code into different versions based on what can be discovered.
  3. I get to learn about all the hidden relationships between entities and attributes that gives me a deeper understanding of what lies beneath.

With that said, this week I needed to access some queues in Dynamics and see what was in them.

To do this, I queried Dynamics for my queue based on the name provided.

QueryExpression query = new QueryExpression();
query.EntityName = "queue";
query.ColumnSet = new ColumnSet(true);
query.Criteria.AddCondition("name", ConditionOperator.Equal, "MySuperQueue");

EntityCollection entityResults = _CrmService.RetrieveMultiple(query);

From here, I was then able to query the queue for what it contains.

if (entityResults.Entities.Count == 1)
{
_CrmQueue = entityResults[0];

_QueueId = new Guid(_CrmQueue["queueid"].ToString());

QueryExpression queryQueues = new QueryExpression();
queryQueues.EntityName = "queueitem";
queryQueues.ColumnSet = new ColumnSet(true);
queryQueues.Criteria.AddCondition("queueid", ConditionOperator.Equal, _QueueId);

EntityCollection entityQueues = _CrmService.RetrieveMultiple(queryQueues);

foreach (Entity ent in entityQueues.Entities)
{
System.Diagnostics.Debug.WriteLine(ent["title"].ToString());
System.Diagnostics.Debug.WriteLine("ENTERED ON: " + ent["enteredon"].ToString());
if (ent.Contains("workeridmodifiedon"))
{
System.Diagnostics.Debug.WriteLine("BEING WORKED ON: " + ent["workeridmodifiedon"].ToString());
}

}
}

I’ll write another post on how to add an item to a queue, because that prevented some logic and general understanding of queues headaches that through me for a loop.

The key fields I want to highlight here are enteredon and workeridmodifiedon (both returning datetime values.  If you are managing a queue, enteredon is the datetime that the item was added to the queue and workeridmodifiedon is the much more important value that shows when the item as picked to be worked on.

A sad fact about Dynamic/CRM queues – all those fancy actions of Pick/Remove/Release – do not change the state of the queueitem in Dynamics which can present for some interesting challenges (a topic for another post).  I have to believe that interfacing with queues would be that much more robust if the status reasons changed as a result.

For now, now you know how to access the items in your queue from your own code.

Getting Started with the USD

If you have not used the USD in Dynamics365 then you’re missing out.

If you’re stuck on how to get started the process is relatively simple and primarily involves downloading the framework and deploying it to your tenant.

To start, download the require components – you will need the framework geared to your OS as well as the Package Deployer- which are all available here – https://www.microsoft.com/en-us/download/details.aspx?id=50355

If you try to open the USD without running the Package Deployer, you’ll receive the following error.

dynamics2

When you execute the Package Deployer, it will ask you where you want to deploy the USD’s solution files to.

dyanmics3

Next you’ll need to selection which package you want to import.  For now – go with the “New Environment” package.

Dynamics4

Once selected, you’ll wait for the solutions to be installed.

Dynamics5

Followed by all the post execution tasks to be executed.Dynamics6

Now if you go back and click the USD icon on your desktop, you’ll get this wonderfully empty canvas from which you can start implementing your solution.

Dynamics7

For now though, you are ready to go.