本文介绍了我需要设置自定义实体的State和StatusCode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用 .Net CRM SDK 设置自定义实体的 State 和 StatusCode 。
以下代码将执行,但是当我检查实体表单时,StatusCode不会更改。
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.
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);
或者您可以这样设置状态:
Or you can set status like this:
int statusCode = 123456;
entity["statuscode"] = new OptionSetValue(statusCode);
_service.Update(entity);
这篇关于我需要设置自定义实体的State和StatusCode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!