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搞清楚我需要投入什么价值?
在任何人问起之前,我们允许客户添加更多,然后只是给定状态的默认状态原因。所以我不能使用LINQ实体附带的枚举。 – 2012-04-10 20:11:24