在Dynamics CRM中,Lead实体既有状态又有状态原因。使用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来确定我需要为?
发布于 2012-04-11 06:32:03
您可以检索带有状态的状态的信息。
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;
}https://stackoverflow.com/questions/10095700
复制相似问题