C# CRM SDK以相同状态重新打开事件并关闭

C# CRM SDK以相同状态重新打开事件并关闭,c#,sdk,dynamics-crm,crm,C#,Sdk,Dynamics Crm,Crm,我可以检索与已关闭事件相关的状态并重新打开该事件。我不明白的是,当 我要结束这件事。我想以重新打开事件之前使用的相同状态关闭事件 //get the incident incident = _service.Retrieve(incident.LogicalName, _incidentId, attributes); //get the status code Int32 tmp_status = Convert.ToInt32(incident["statuscode"]); //DOES

我可以检索与已关闭事件相关的状态并重新打开该事件。我不明白的是,当 我要结束这件事。我想以重新打开事件之前使用的相同状态关闭事件

//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);
试着换线

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

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