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

Announcements

No record found.

News and Announcements icon
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

    Hello Tahir,

    You are using "incident_statuscode" is it an object or not ?

  • Community Member Profile Picture
    on at

    Hi,

    I copy this code from MS site, for which entity I need to create object for "incident_statuscode". I want to close the incident , I tried different options but its not working , can you share some working code ?

    Thanks

  • Suggested answer
    Community Member Profile Picture
    on at

    SetStateRequest request = new SetStateRequest();

                      request.State = new OptionSetValue(1);

                   request.Status =new OptionSetValue(5);

    use this. Hope it will help for you!

  • Community Member Profile Picture
    on at

    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

    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 :)

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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
    gdas Profile Picture
    50,091 Moderator on at

    Hello ,

    You can also refer Aric's blogs here-

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

  • Community Member Profile Picture
    on at

    Hi,

    which object is incident_statuscode  ????

  • Community Member Profile Picture
    on at

    Now I am getting below error:

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

    Thanks

  • Suggested answer
    Community Member Profile Picture
    on at

    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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
AS-17030037-0 Profile Picture

AS-17030037-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans