2016-12-13 7 views
0

Я могу получить статус, связанный с закрытым инцидентом, и повторно открыть этот инцидент. Я не могу понять, как использовать предыдущий статус, когда Я заново закрываю инцидент. Я хочу закрыть инцидент с тем же статусом, который использовался до того, как я его снова открыл.CRM SDK для повторного открытия инцидента и закрытия с таким же статусом

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

ответ

1

Попробуйте заменить линию

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

с линией

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