Dynamics crm 2011 如何在MS CRM查询表达式中添加optionset筛选条件?
我有一个具有两个属性的实体类型,1。类型,2。可用天数,其中类型为optionset,可用天数为文本字段。我想获取所有这样的LeaveType记录,其中OptiStart中选择的Type='Yearal'。我无法找到如何在选项集值的查询表达式中添加筛选器。以下是我正在使用的方法:Dynamics crm 2011 如何在MS CRM查询表达式中添加optionset筛选条件?,dynamics-crm-2011,crm,query-expressions,Dynamics Crm 2011,Crm,Query Expressions,我有一个具有两个属性的实体类型,1。类型,2。可用天数,其中类型为optionset,可用天数为文本字段。我想获取所有这样的LeaveType记录,其中OptiStart中选择的Type='Yearal'。我无法找到如何在选项集值的查询表达式中添加筛选器。以下是我正在使用的方法: public Entity Getleavetype(Guid LeaveDetailsId, IOrganizationService _orgService, CodeActivityContext Acontex
public Entity Getleavetype(Guid LeaveDetailsId, IOrganizationService _orgService, CodeActivityContext Acontext)
{
QueryExpression GetLeavedetails = new QueryExpression();
GetLeavedetails.EntityName = "sgfdhr_leavetype";
GetLeavedetails.ColumnSet = new ColumnSet("new_type");
GetLeavedetails.ColumnSet = new ColumnSet("new_availabledays");
GetLeavedetails.Criteria.AddCondition("new_type", ConditionOperator.Equal, "Annual" ); //Is this correct????
GetLeavedetails.Criteria.AddCondition("new_employeeleavecalculation", ConditionOperator.Equal, LeaveDetailsId); //ignore this
//((OptionSetValue)LeaveDetailsId["new_leavetype"]).Value
EntityCollection LeaveDetails = _orgService.RetrieveMultiple(GetLeavedetails);
return LeaveDetails[0];
}
在您的情况下,您需要设置optionset的整数值,而不是标签 假设年值为例2,则代码为:
GetLeavedetails.Criteria.AddCondition("new_type", ConditionOperator.Equal, 2);
在您的情况下,您需要设置optionset的整数值,而不是标签 假设年值为例2,则代码为:
GetLeavedetails.Criteria.AddCondition("new_type", ConditionOperator.Equal, 2);
您应该使用RetrieveAttributeRequest来查找OptionSet文本的int值
在我的代码中,它看起来像:
private static int findParkedOptionValue(IOrganizationService service)
{
RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest
{
EntityLogicalName = Model.Invite.ENTITY_NAME,
LogicalName = Model.Invite.COLUMN_STATUS,
RetrieveAsIfPublished = false
};
// Execute the request
RetrieveAttributeResponse attributeResponse =
(RetrieveAttributeResponse)service.Execute(attributeRequest);
var attributeMetadata = (EnumAttributeMetadata)attributeResponse.AttributeMetadata;
// Get the current options list for the retrieved attribute.
var optionList = (from o in attributeMetadata.OptionSet.Options
select new { Value = o.Value, Text = o.Label.UserLocalizedLabel.Label }).ToList();
int value = (int)optionList.Where(o => o.Text == "Парковка")
.Select(o => o.Value)
.FirstOrDefault();
return value;
}
在中,您找到了一个完美的示例。您应该使用RetrieveAttributeRequest来查找OptionSet文本的int值
在我的代码中,它看起来像:
private static int findParkedOptionValue(IOrganizationService service)
{
RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest
{
EntityLogicalName = Model.Invite.ENTITY_NAME,
LogicalName = Model.Invite.COLUMN_STATUS,
RetrieveAsIfPublished = false
};
// Execute the request
RetrieveAttributeResponse attributeResponse =
(RetrieveAttributeResponse)service.Execute(attributeRequest);
var attributeMetadata = (EnumAttributeMetadata)attributeResponse.AttributeMetadata;
// Get the current options list for the retrieved attribute.
var optionList = (from o in attributeMetadata.OptionSet.Options
select new { Value = o.Value, Text = o.Label.UserLocalizedLabel.Label }).ToList();
int value = (int)optionList.Where(o => o.Text == "Парковка")
.Select(o => o.Value)
.FirstOrDefault();
return value;
}
在中,您找到了一个完美的例子。谢谢Guido。您还可以帮助我使用以下代码字符串value=OptionSetValueLeaveDetails[new\u leavetype].value.toString;//我需要获取选项集的字符串值,而不是整数值。对于需要查询元数据的标签,这里有一个示例:谢谢Guido。您还可以帮助我使用以下代码字符串value=OptionSetValueLeaveDetails[new\u leavetype].value.toString;//我需要获取选项集的字符串值,而不是整数值。对于标签,您需要查询元数据,以下示例: