2

在 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 以确定我需要为 ???

4

1 回答 1

3

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

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;
}
于 2012-04-10T22:32:02.620 回答