Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Closure of Incident from C#

Posted on by Microsoft Employee

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

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

    is this working?

  • Community Member Profile Picture
    Community Member Microsoft Employee 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
    Community Member Microsoft Employee 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
    Community Member Microsoft Employee 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
    Community Member Microsoft Employee on at
    RE: Closure of Incident from C#

    Hi,

    which object is incident_statuscode  ????

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 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
    gdas 50,085 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
    Community Member Microsoft Employee 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
    Community Member Microsoft Employee 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
    Community Member Microsoft Employee 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans