views:

103

answers:

3

Hello everybody,

I'm trying to resolve/close Dynamics CRM4 cases/incidents through webservices.

A single SetStateIncidentRequest is not enough and returns a Server was unable to process request error message. I think it has something to do with active workflows that trigger on case's attribute changes. I don't know if there's anything else preventing the request to work.

Since it is possible to close those cases through the GUI, I guess there's a "correct" set of steps to follow in order to achieve it through CrmService; unfortunately, I've been googleing it for a while without finding what I want. Could anybody help me, please?

A: 

Here's a tip - catch the SoapException and examine the Detail.OuterXML property and you will get a more detailed error message. It's possible you're not building your request correctly.

brendan
BTW, thanks, the tip is very useful for debugging!
Rafael D.
A: 

Indeed, I didn't know that there exists a CloseIncidentRequest class to use with the CrmService.Execute() method. Most probably the SetStateIncidentRequeset won't work because it's expected that incident resolutions are created that way. Pity that names for classes and actions aren't used consistently (case/incident, resolution/closing)...

Rafael D.
A: 

To resolve a case in CRM (in VB.NET), I do the following:

Try

Dim activity As New incidentresolution
Dim closeRequest As New CloseIncidentRequest
Dim closeResponse As New CloseIncidentResponse
Dim strErrors As String = String.Empty()

activity.incidentid = New Lookup
activity.incidentid.type = EntityName.incident.ToString
activity.incidentid.Value = //[GUID OF INCIDENT]

activity.ownerid = New Owner
activity.ownerid.type = EntityName.systemuser.ToString
activity.ownerid.Value = //[GUID OF USER PERFORMING ACTION]

activity.statecode = New IncidentResolutionStateInfo
activity.statecode.Value = 1 //Resolved

activity.statuscode = New Status
activity.statuscode.Value = 5 //Problem Solved

closeRequest.IncidentResolution = activity
closeRequest.Status = 5 //Problem Solved

// IF REQUIRED:
activity.timespent = New CrmNumber
activity.timespent.Value = //[INTEGER REPRESENTING No. OF MIN SPENT ON CASE]

closeResponse = objCrm.Execute(closeRequest)

Catch ex As System.Web.Services.Protocols.SoapException

    Dim root As XmlElement = ex.Detail
    strErrors = strErrors & vbCrLf & vbCrLf & root.ChildNodes(0).ChildNodes(3).InnerText

    Return False

End Try
Brian