Thursday, May 10, 2018

Sample RemoveFromQueueRequest - Dynamics 365


public void removeRecordFromQueue(Guid entId, IOrganizationService service)
{

    string queueItemQuery = @"<fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'>
                        <entity name='queueitem'>
                            <attribute name='queueitemid' />
                            <filter type='and'>
                                   <condition attribute='objectid' value='{0}' operator='eq'/>
                            </filter>
                          </entity>
                        </fetch>";

    queueItemQuery = string.Format(queueItemQuery, entId.ToString());

    EntityCollection returnEntityCollection = service.RetrieveMultiple(new FetchExpression(queueItemQuery));

    foreach (var returnEntity in returnEntityCollection.Entities)
    {       
        RemoveFromQueueRequest removeFromQueueRequest = new RemoveFromQueueRequest
        {
            QueueItemId = returnEntity.Id
        };
        service.Execute(removeFromQueueRequest);
    }
}

No comments:

Post a Comment