gpt4 book ai didi

c# - 无法在 CRM 中创建记录

转载 作者:行者123 更新时间:2023-11-30 23:06:35 24 4
gpt4 key购买 nike

我想在 CRM 中创建一个赢得机会,但出现以下错误。

错误:

Additional information: 3 is not a valid status code for state code OpportunityState.Open on opportunity with Id 8e99128b-3ef0-e711-8145-e0071b6641f1.

代码:

 public void CreateOpportunity()
{
Entity opportunity = new Entity("opportunity");
opportunity["name"] = "ABC";
opportunity["statecode"] = new OptionSetValue(1);
opportunity["statuscode"] = new OptionSetValue(3);
crmService.Create(opportunity);
}

最佳答案

在 CRM 中,状态代码是只读。添加记录时不能动态设置它,因此您会在问题中遇到错误。

要通过它,您需要使用 SetStateRequest .

你初始化一个新的 SetStateRequest 类并设置它,来自 msdn 示例:

// Create the Request Object
SetStateRequest state = new SetStateRequest();

// Set the Request Object's Properties
state.State = new OptionSetValue((int)IncidentState.Active);
state.Status =
new OptionSetValue((int)incident_statuscode.WaitingforDetails);

// Point the Request to the case whose state is being changed
state.EntityMoniker = caseReference;

// Execute the Request
SetStateResponse stateSet = (SetStateResponse)_serviceProxy.Execute(state);

// Check if the state was successfully set
Incident incident = _serviceProxy.Retrieve(Incident.EntityLogicalName,
_caseIncidentId, new ColumnSet(allColumns: true)).ToEntity<Incident>();

if (incident.StatusCode.Value == (int)incident_statuscode.WaitingforDetails)
{
Console.WriteLine("Record state set successfully.");
}
else
{
Console.WriteLine("The request to set the record state failed.");
}

和 IncidentState 值列表:

IncidentStateSNC.NEW                = "1";

IncidentStateSNC.IN_PROGRESS = "2";

IncidentStateSNC.ACTIVE = IncidentStateSNC.IN_PROGRESS;

IncidentStateSNC.ON_HOLD = "3";

IncidentStateSNC.AWAITING_PROBLEM = IncidentStateSNC.ON_HOLD;

IncidentStateSNC.AWAITING_USER_INFO = IncidentStateSNC.ON_HOLD;

IncidentStateSNC.AWAITING_EVIDENCE = IncidentStateSNC.ON_HOLD;

IncidentStateSNC.RESOLVED = "6";

IncidentStateSNC.CLOSED = "7";

IncidentStateSNC.CANCELED = "8";

这里有一篇关于 How to set the state on dynamic entity 的好文章

关于c# - 无法在 CRM 中创建记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48071330/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com