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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Closing Incident with Cancelled Status

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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

  • GandeShiva Profile Picture
    105 on at

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

    Thanks for reply

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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
    105 on at

    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

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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
    105 on at

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

  • Verified answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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
    105 on at

    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

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans