我需要设置使用.net CRM SDK的自定义实体的国家和的StatusCode。
下面的代码执行,但是当我检查的实体形式的的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);
}
你可以试试下面的代码,我用这个代码来设置状态。
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);