Skip to main content

Notifications

Announcements

No record found.

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

  • Community Member Profile Picture
    on at
    RE: Error while updating a case/incident record from web application

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

    community.dynamics.com/.../272431

    Thanks in advance :)

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Error while updating a case/incident record from web application

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

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Error while updating a case/incident record from web application

    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;

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

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans