4

我需要使用.Net CRM SDK设置自定义实体的StateStatusCode。 以下代码执行,但当我检查实体表单时,StatusCode 没有更改。

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);
}
4

1 回答 1

13

您可以尝试以下代码,我使用此代码设置状态。

Microsoft.Xrm.Sdk.EntityReference moniker = new EntityReference();
moniker.LogicalName = "contract";
moniker.Id = newContractId;

Microsoft.Xrm.Sdk.OrganizationRequest request 
  = new Microsoft.Xrm.Sdk.OrganizationRequest() { RequestName = "SetState" };
request["EntityMoniker"] = moniker;
OptionSetValue state = new OptionSetValue(1);
OptionSetValue status = new OptionSetValue(2);
request["State"] = state;
request["Status"] = status;

_service.Execute(request);

或者您可以像这样设置状态:

int statusCode = 123456;
entity["statuscode"] = new OptionSetValue(statusCode);
_service.Update(entity);
于 2012-10-02T10:00:34.193 回答