Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Closing Incident with Cancelled Status

Posted on by 105

I'm trying to Close case with "CANCELED" status. If i wrote "5" for changeIncidentStatusRequest.Status it's succesfully Closing case with "RESOLVED" but when i wrote 6 ( Canceled status code) i get this exception :

" 6 is not a valid status code for state

Entity resolution = new Entity("incidentresolution");
resolution["subject"] = "Incident Closed";
resolution["incidentid"] = incident;

CloseIncidentRequest closeRequest = new CloseIncidentRequest();
closeRequest.IncidentResolution = resolution;
closeRequest.Status = new OptionSetValue(6);
CloseIncidentResponse closeResponse = (CloseIncidentResponse)service.Execute(closeRequest);

Please help...

*This post is locked for comments

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Closing Incident with Cancelled Status

    From what I remember, cancelled doesn't have a resolution, that is why you just make the changes on the Incident entity and not the IncidentResolution entity.

  • GandeShiva Profile Picture
    GandeShiva 105 on at
    RE: Closing Incident with Cancelled Status

    It worked with setstateRequest but what about the incidentresolution (Can you refer my question for the code). Do i need to do any extra logic for that

  • Verified answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Closing Incident with Cancelled Status

    You can use the SetStateRequest as well. Same thing.

    The StateStateIncidentRequest is probably part of Microsoft.Xrm.Sdk.Messages or Microsoft.Crm.Sdk.Messages;

    SetStateRequest request = new SetStateRequest();

    request.EntityMoniker = new EntityReference(...);

    request.State = new OptionSetValue(2);

    request.Status = new OptionSetValue(6);

  • GandeShiva Profile Picture
    GandeShiva 105 on at
    RE: Closing Incident with Cancelled Status

    The type or namespace name 'SetStateIncidentRequest' could not be found (are you missing a using directive or an assembly reference?)

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Closing Incident with Cancelled Status

    Got it.

    I think you need to use the SetStateIncidenRequest Message

    SetStateIncidentRequest request = new SetStateIncidentRequest()

    {

      IncidentState = new OptionSetValue(2); // Cancelled

      IncidentStatus = new OptionSetValue(6); // Cancelled

      EntityId = new EntityReference("incident", incidentId)

    }

    Try this. Hopefully it helps.

  • GandeShiva Profile Picture
    GandeShiva 105 on at
    RE: Closing Incident with Cancelled Status

    it's successfully Closing case with "RESOLVED" but when i wrote 6 ( Canceled status code) i get this exception :

    " 6 is not a valid status code for state

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Closing Incident with Cancelled Status

    Just change the following line:

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

    to

    Status = new OptionSetValue(6); or

    Status = (int)incident_statuscode.Cancelled) // Check name

  • GandeShiva Profile Picture
    GandeShiva 105 on at
    RE: Closing Incident with Cancelled Status

    I am using the above code for Incident Resolved.. I need for Cancelled..

    Thanks for reply

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Closing Incident with Cancelled Status

    try the following:

    IncidentResolution resolution = new IncidentResolution

    {

      Subject = "Resolved Sample Incident",

      IncidentId = new EntityReference(Incident.EntityLogicalName, _incidentId)

    };

    // Close the incident with the resolution.

    CloseIncidentRequest closeIncidentRequest = new CloseIncidentRequest

    {

      IncidentResolution = incidentResolution,

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

    };

    CloseIncidentResponse closeResponse = (CloseIncidentResponse)service.Execute(closeIncidentRequest);

    You can use late binding as well, but make sure that incidentid is an EntityReference

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