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;

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.


Post A Reply

%d bloggers like this: