g.lowell
g.lowell

Reputation: 21

CRM SDK to re-open incident and close with same status

I can retrieve the status related to a closed incident and re-open that incident. What I can't understand is how to use the previous status when I re-close the incident. I want to close the incident with the same status used before I had re-opened it.

//get the incident
incident = _service.Retrieve(incident.LogicalName, _incidentId, attributes);
//get the status code
Int32 tmp_status = Convert.ToInt32(incident["statuscode"]); //DOES NOT WORK
//open incident
SetStateRequest state = new SetStateRequest();
state.EntityMoniker = new EntityReference("incident", _incidentId);
state.State = new OptionSetValue(0);
state.Status = new OptionSetValue(4);
SetStateResponse stateSet = (SetStateResponse)_serviceProxy.Execute(state);

//close incident
var incidentResolution = new IncidentResolution
{
    Subject = "Incident Resolved",
    IncidentId = new EntityReference(Incident.EntityLogicalName, _incidentId)
};
var closeIncidentRequest = new CloseIncidentRequest
{
    IncidentResolution = incidentResolution,
    Status = new OptionSetValue(tmp_status) //Can't get the syntax of how to use tmp_status
};

_serviceProxy.Execute(closeIncidentRequest);

Upvotes: 1

Views: 1546

Answers (1)

Andrew Butenko
Andrew Butenko

Reputation: 5456

Try to replace line

Int32 tmp_status = Convert.ToInt32(incident["statuscode"]);

with line

Int32 tmp_status = incident.GetAttributeValue<OptionSetValue>("statuscode").Value;

Upvotes: 1

Related Questions