gpt4 book ai didi

c# - 从 Leads "Status"获取 Leads "Status Reason"

转载 作者:行者123 更新时间:2023-11-30 22:29:40 30 4
gpt4 key购买 nike

在 Dynamics CRM 中,潜在客户实体同时具有状态和状态原因。使用 API 我可以获得所有状态原因。我被绊倒的地方是当我的用户选择状态原因时我想倒退并找出哪个状态与所选状态原因相关联。

以下是我如何获得所有状态原因:

 //get the list of status reasons 
RetrieveAttributeRequest request = new RetrieveAttributeRequest();
request.EntityLogicalName = "lead";
request.LogicalName = "statuscode";

RetrieveAttributeResponse response = RetrieveAttributeResponse)theOrgContext.Execute(request);
StatusAttributeMetadata picklist = (StatusAttributeMetadata)response.AttributeMetadata;
foreach (OptionMetadata option in picklist.OptionSet.Options)
{
retval.ListOfStatuses.Add(option.Value.Value, option.Label.UserLocalizedLabel.Label.ToString());
}

要更新实体,我只使用 LINQ:

 //set the status to the new value
theLead.StatusCode.Value = int.Parse(statusValue);

theLead.StateCode = ???

//mark the object as updated
theContext.UpdateObject(theLead);

//persist the changes back to the CRM system
theContext.SaveChanges();

我只是不知道如何查询 CRM 来确定我需要为 ??? 输入什么值

最佳答案

您可以使用 status 检索状态的信息。

RetrieveAttributeRequest req = new RetrieveAttributeRequest();
req.EntityLogicalName = "lead";
req.LogicalName = "statuscode";
req.RetrieveAsIfPublished = true;
RetrieveAttributeResponse res = (RetrieveAttributeResponse)yourContext.Execute(req);

StatusAttributeMetadata attribute = (StatusAttributeMetadata)res.AttributeMetadata;
foreach (StatusOptionMetadata oStatusOptionMetaData in attribute.OptionSet.Options)
{
var state = oStatusOptionMetaData.State.Value;
var status = oStatusOptionMetaData.Value.Value;
}

关于c# - 从 Leads "Status"获取 Leads "Status Reason",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10095700/

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