I'm creating a plugin with SetStateRequest inside. The plugin registered on Create message in Case Entity. The idea is to set the Status (Cancelled) of new Case if meets some criteria.
Here the code:
if (!String.IsNullOrEmpty(customer_name)) { QueryExpression query_contacy = new QueryExpression("new_listinternal"); query_contacy.ColumnSet = new ColumnSet(true); EntityCollection ent = _service.RetrieveMultiple(query_contacy); foreach (Entity e in ent.Entities) { if (e.Attributes.Contains("new_email")) { emil = e.GetAttributeValue<String>("new_email"); if(customer_name.Equals(emil)) { try { SetStateRequest stateReq = new SetStateRequest(); stateReq.EntityMoniker = (EntityReference)entity.ToEntityReference(); stateReq.State = new OptionSetValue(2); stateReq.Status = new OptionSetValue(6); SetStateResponse response = new SetStateResponse(); response = (SetStateResponse)_service.Execute(stateReq); } catch (Exception ex) { throw new InvalidPluginExecutionException(ex.Message); } } } } }
When i test create a record that meets the condition. It's throw an error that says the Guid Of the records doesn't exist.
<ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic">
<KeyValuePairOfstringanyType>
<d2p1:key>OperationStatus</d2p1:key>
<d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema" i:type="d4p1:string">0</d2p1:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<d2p1:key>SubErrorCode</d2p1:key>
<d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema" i:type="d4p1:string">-2146233088</d2p1:value>
</KeyValuePairOfstringanyType>
</ErrorDetails>
<Message>incident With Id = 017e981c-5db2-e711-80be-a4934caa8811 Does Not Exist</Message>
<Timestamp>2017-10-16T10:31:05.1266682Z</Timestamp>
<ExceptionSource i:nil="true" />
<InnerFault i:nil="true" />
<OriginalException i:nil="true" />
<TraceText>
*This post is locked for comments