Using this code, I can set the state and status of a CRM object in C #.
SetStateRequest appointmentRequest = new SetStateRequest
{
State = new OptionSetValue(3),
Status = new OptionSetValue(5),
EntityMoniker = new EntityReference("appointment", myEntity.Id)
};
crmsvc.Execute(appointmentRequest);
A few lines before that I create the same object with
crmsvc.Create(myEntity);
Doing this in two queries seems dumb, so I went looking for a way to do this in one query.
Found this question. I need to set State and StatusCode for a custom object , and it seems that the status code can be set before saving, but I can’t find any patterns that do this also with state.
Tried to do it, but it didn’t work
myEntity["state"] = new OptionSetValue(3);
He throws back:
The entity does not contain an attribute with the name = 'state'. (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault) .: The 'Entity' object does not contain an attribute with the name = 'state'.
, - ?