如何通过webservice取消MS CRM中的案例(事件)

时间:2010-09-13 12:55:26

标签: dynamics-crm dynamics-crm-4

问题:如何使用WebService取消Microsoft CRM 4中的案例(突发事件)?

我写这篇文章是因为我花了很长时间才找到正确的答案,MS的文档在这方面并没有多大帮助,希望这会为其他人节省时间。

2 个答案:

答案 0 :(得分:3)

答案(在VB.NET中):

 Dim CancelRequest As New SetStateIncidentRequest
    CancelRequest.IncidentState = IncidentState.Canceled
    CancelRequest.IncidentStatus = -1
    CancelRequest.EntityId = // [GUID OF INCIDENT]

    Dim CancelResponse As New SetStateIncidentResponse

    Try

        CancelResponse = objCrm.Execute(CancelRequest)

    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

    Catch ex As Exception

        strErrors = strErrors & vbCrLf & vbCrLf & ex.Message

        Return False

    End Try

    Return True

其中objCRM是CrmService的一个实例。

答案 1 :(得分:1)

以下是CRM2011的C#版本。

 try
 {
     SetStateRequest stateRequest = new SetStateRequest();
     stateRequest.EntityMoniker = (EntityReference)entity.ToEntityReference();
     stateRequest.State = new OptionSetValue(2); //Code - Cancelled.
     stateRequest.Status = new OptionSetValue(6); // Reason - Cancelled. 

     SetStateResponse response = new SetStateResponse();
     response = (SetStateResponse)service.Execute(stateRequest);
 }
 catch (Exception ex)
 {
     // Catch exception & do whatever you want man... :)
 }