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

发布于 2024-09-18 12:13:28 字数 114 浏览 6 评论 0原文

问题:如何使用 Web 服务取消 Microsoft CRM 4 中的案例(事件)?

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

The Question: How to cancel a Case (Incident) in Microsoft CRM 4 using the WebService?

I'm writing this because it took me ages to find the right answer and MS's documentation is not very helpful in this regard, hopefully this will save time for other people.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

对风讲故事 2024-09-25 12:13:28

答案(在 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 的一个实例。

The Answer (in 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

Where objCRM is an instance of the CrmService.

温柔戏命师 2024-09-25 12:13:28

这是 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... :)
 }

Here is the C# version for CRM2011.

 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... :)
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文