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)

Error while updating a case/incident record from web application

(0) ShareShare
ReportReport
Posted on by

I have to reopen a case ( incident ) through my code and then update a field and again close it as resolved.

I am able to open it using SetStateRequest and close it using CloseIncidentRequest. But in between I am not able to use service.Update(caseRecord) to update it. I get the error "This message cannot be used to Close the incident. Use CloseIncidentRequest to close the case". What should I do to update the record ? 

SetStateRequest state = new SetStateRequest();
state.State = new OptionSetValue(0); // set the case status to Active
state.Status = new OptionSetValue(1); // set the case status reason to "In Progress"
state.EntityMoniker = record.ToEntityReference();
SetStateResponse stateSet = (SetStateResponse)service.Execute(state);
record["merc_originalowner"] = new EntityReference("systemuser", currentOwner.Id);

record["statuscode"]= new OptionSetValue(1); 
service.Update(record);         //                               this line gives error

Entity incidentResolution = new Entity("incidentresolution");
incidentResolution["subject"] = "Resolved";
incidentResolution["incidentid"] = new EntityReference ("incident",record.Id);
CloseIncidentRequest closeRequest = new CloseIncidentRequest();
closeRequest.IncidentResolution = incidentResolution;

*This post is locked for comments

I have the same question (0)
  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    try this code-

    ============

    SetStateRequest state = new SetStateRequest();

                   state.State = new OptionSetValue(0); // set the case status to Active

                   state.Status = new OptionSetValue(1); // set the case status reason to "In Progress"

                   state.EntityMoniker = record.ToEntityReference();

                   SetStateResponse stateSet = (SetStateResponse)service.Execute(state);

                   // Create a new instance for update

                   Entity recodUpd = new Entity(record.LogicalName, record.Id);

                   recodUpd["merc_originalowner"] = new EntityReference("systemuser", currentOwner.Id);

                   recodUpd["statuscode"] = new OptionSetValue(1);

                   service.Update(record);        

                   Entity incidentResolution = new Entity("incidentresolution");

                   incidentResolution["subject"] = "Resolved";

                   incidentResolution["incidentid"] = new EntityReference("incident", record.Id);

                   CloseIncidentRequest closeRequest = new CloseIncidentRequest();

                   closeRequest.IncidentResolution = incidentResolution;

    ==================

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

    Hi Bob,

    As Ravi  mentioned you need to create new instance of the record when you are updating instead of reusing the same before update.
    record["merc_originalowner"] = new EntityReference("systemuser", currentOwner.Id);

    // Create a new instance for update

    Entity recodUpd = new Entity(record.LogicalName, record.Id);

  • Community Member Profile Picture
    on at

    Hi Ravi, I need some help in solving an issue. Please follow the link :

    community.dynamics.com/.../272431

    Thanks in advance :)

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 April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans