web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Closure of Incident from C#

(0) ShareShare
ReportReport
Posted on by

Hi Everyone,

I want to close an incident from c# code, I am using the below mention code. but I am getting following error :

The name 'incident_statuscode' does not exist in the current context.

  SetStateRequest request = new SetStateRequest();
                   request.State = new OptionSetValue((int)IncidentState.Resolved);
                request.Status =new OptionSetValue((int)incident_statuscode.Resolved;

                request.Status = new OptionSetValue((int)Incident.OptionSets.StatusCode.ProblemSolved);
                request.EntityMoniker = SRItemReference;

                SetStateResponse response = (SetStateResponse)StaticXrmService.Proxy.Execute(request);

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Closure of Incident from C#

    is this working?

  • Community Member Profile Picture
    on at
    RE: Closure of Incident from C#

    HI

      var incidentResolution = new IncidentResolution

                   {

                       Subject = "Resolved Sample Incident",

                       IncidentId = new EntityReference(Incident.EntityLogicalName, _crmSRItem.Id)

                   };

                   //<snippetCloseAnIncident2>

                   // Close the incident with the resolution.

                   var closeIncidentRequest = new CloseIncidentRequest

                   {

                       IncidentResolution = incidentResolution,

                       Status = new OptionSetValue((int)incident_statuscode.ProblemSolved)

                   };

                   _serviceProxy.Execute(closeIncidentRequest);

    Thanks

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Closure of Incident from C#

    where you are using bellow code:-

    EntityReference SRItemReference = new EntityReference()

                  {

                      LogicalName = Incident.EntityLogicalName,

                      Id = _crmSRItem.Id

                  };

    Please check

    1. _crmSRItem.Id is a correct  correct object

    2. Here pass record ID

    3. you can use a string "incident" instead of Incident.EntityLogicalName

  • Community Member Profile Picture
    on at
    RE: Closure of Incident from C#

    Now I am getting below error:

    5 is not a valid status code on incident with Id 00000000-0000-0000-0000-000000000000.

    Thanks

  • Community Member Profile Picture
    on at
    RE: Closure of Incident from C#

    Hi,

    which object is incident_statuscode  ????

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Closure of Incident from C#

    Hello ,

    You can also refer Aric's blogs here-

    community.dynamics.com/.../closing-incident-record

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Closure of Incident from C#

    Hi ,

    Could you please use below code .

    Hope this helps

    IncidentResolution resolution = new IncidentResolution
    {
       Subject = "Resolved Incident",
       IncidentId = new EntityReference(Incident.EntityLogicalName, _incidentId)
    };
    
    // Close the incident with the resolution.
    CloseIncidentRequest request = new CloseIncidentRequest
    {
       IncidentResolution = incidentResolution,
       Status = new OptionSetValue((int)incident_statuscode.ProblemSolved)
    };
    
    CloseIncidentResponse closeResponse = (CloseIncidentResponse)service.Execute(closeIncidentRequest);

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Closure of Incident from C#

    Please follow this link

    social.microsoft.com/.../how-to-close-case-programatically-in-crm-2011-from-within-plugin

    Hope you can understand it other wise i am here :)

  • Community Member Profile Picture
    on at
    RE: Closure of Incident from C#

    Hi,

    Now I am getting following error message :

    "This message can not be used to set the state of incident to Closed.  In order to set state of incident to Closed, use the CloseIncidentRequest message instead"

    Below is my code

    EntityReference SRItemReference = new EntityReference()

                   {

                       LogicalName = Incident.EntityLogicalName,

                       Id = _crmSRItem.Id

                   };

                   SetStateRequest request = new SetStateRequest();

                   //   request.State = new OptionSetValue((int)Incident.OptionSets.StateCode.Resolved);

                   request.State = new OptionSetValue(1);

                   request.Status =new OptionSetValue(5);

                  // request.Status = new OptionSetValue((int)Incident.OptionSets.StatusCode.ProblemSolved);

                   request.EntityMoniker = SRItemReference;

                   SetStateResponse response = (SetStateResponse)StaticXrmService.Proxy.Execute(request);

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Closure of Incident from C#

    SetStateRequest request = new SetStateRequest();

                      request.State = new OptionSetValue(1);

                   request.Status =new OptionSetValue(5);

    use this. Hope it will help for you!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans