I need to set the State and StatusCode of a custom entity using the .Net CRM SDK.
The following code executes but the StatusCode isn’t changed when I check on the entity form.
private void SetState(Entity entity, int statuscode)
{
SetStateRequest setState = new SetStateRequest
{
EntityMoniker = new EntityReference(
entity.LogicalName, new Guid(entity.Id.ToString())),
State = new OptionSetValue(0),
Status = new OptionSetValue(statuscode)
};
SetStateResponse myres = (SetStateResponse)svc.Execute(setState);
}
You may try the following code, I use this code to set state.
Or you can set status like this: