2010-09-13 15 views

Répondre

3

La réponse (en 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 

Où objCRM est une instance de la CrmService.

1

Voici la version C# pour 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... :) 
}