1

I have a few things that work together to complete multiple task from a queue.

The first is javascript which calls an Action (Workflow) handing a CSV of task ids and the users id. This action hands it all over the a plugin which loops the tasks, picks them for the user and then sets them to complete.

This all runs great unless a task is already assigned. I then get an error from the javascript.

enter image description here

At first this was saying "Item has already been assigned to another user". However I added a try catch as such

try
{
    Entity queueItem = RetrieveQueueItemIdByObjectId(service, new Guid(taskId));

    // Create the Request Object and Set the Request Object's Properties
    PickFromQueueRequest pickFromQueueRequest = new PickFromQueueRequest
    {
        QueueItemId = queueItem.Id,
        WorkerId = new Guid(_UserId)
    };
    // Execute the Request
    service.Execute(pickFromQueueRequest);
}
catch(FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
{
    if (ex.Detail.ErrorCode != -2147220891)
    {
        throw ex;
    }
}

I have tried that catch with

if(!ex.Message.Contains("Item has already been assigned to another user"))
{
    throw ex;
}

and just catching everything. And yet the error still shows. I then noticed the tasks were completing, but the error is getting thrown. After this code is where the task is set to complete. Which works because if the task is not already picked, no error is thrown.

1
  • How about skipping this record from completion as this is already assigned? I think basically you have to release this queue item before pick it again.. Commented Nov 2, 2017 at 12:58

2 Answers 2

1

The answer is in the error: in a plugin you cannot catch exceptions thrown by the OrganizationService (or any exception actually, as far as I'm aware of) and continue running.

You have to expand your code so it doesn't throw if you want it to work. No way around this.

Sign up to request clarification or add additional context in comments.

3 Comments

I have attached to the process and in the plugin, no exception is thrown
Oh wait, I get what you mean. I can not use try catch to see if the record is assigned. I should check to see if it is assigned first.
To solve this instead of using a try catch to determine if the queueitem had been assigned, I did an if statement to check myself.
0

and just catching everything. And yet the error still shows. I then noticed the tasks were completing, but the error is getting thrown. After this code is where the task is set to complete. Which works because if the task is not already picked, no error is thrown.

How about skipping this record from completion as this is already assigned? Basically you have to release this queue item before picking it again.

ReleaseToQueueRequest or RemoveFromQueueRequest

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.