Wednesday, January 19, 2011

CRM 4.0 - присвоение инцидента очереди

У меня была задача в соответствии с которой мне необходимо было присвоить инцидент в произвольную очередь. В MSDN есть замечательный пример. Но этот пример не работал в ситуации когда инцидент принадлежал не в очереди "In Progress" пользователя. Код далее работает универсально.



string fetchRequest = string.Format(@"<fetch mapping='logical'>
<entity name='queueitem'>
<attribute name='queueid'/>
<filter type='and'>
<condition attribute='objectid' operator='eq' value='{0}'/>
</filter>
</entity>
</fetch>", Guid.Empty);//Insert identifier of incident here

string fetchResponce = string.Empty;

try
{
fetchResponce = crmservice.Fetch(fetchRequest);
}
catch (SoapException sexc)
{
throw new Exception(sexc.Detail.InnerText);
}

XmlDocument doc = new XmlDocument();
doc.LoadXml(fetchResponce);

XmlNode queueidnode = doc.SelectSingleNode("//resultset/result/queueid");

TargetQueuedIncident target = new TargetQueuedIncident();
target.EntityId = Guid.Empty;//Insert identifier of your incident here

RouteRequest routerequest = new RouteRequest();
routerequest.EndpointId = Guid.Empty;//Insert Identifier of queue here
routerequest.RouteType = RouteType.Queue;

if (queueidnode != null)
routerequest.SourceQueueId = new Guid(queueidnode.InnerText);
else
throw new Exception("Queue was not found");

routerequest.Target = target;

try
{
crmservice.Execute(routerequest);
}
catch (SoapException sexc)
{
throw new Exception(sexc.Detail.InnerText);
}

No comments:

Post a Comment