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)

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

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