构建名称字段为 A 或 B 的 QueryExpression
我正在尝试构建 Dynamics CRM 4 查询,以便可以获得名为“事件 A”或“事件 B”的日历事件。
QueryByAttribute 似乎无法完成这项工作,因为我无法指定“event_name”=“Event B”的“event_name”=“Event A”字段的条件。
使用 QueryExpression 时,我发现 FilterExpression 适用于引用实体。我不知道 FilterExpression 是否可以在引用实体上使用。下面的示例类似于我想要实现的目标,尽管这会返回一个空结果集,因为它将在名为“my_event_response”的实体中查找“name”属性。看起来我需要运行多个查询才能获得此结果,但这比我一次提交所有查询的效率要低。
ColumnSet columns = new ColumnSet();
columns.Attributes = new string[]{ "event_name", "eventid", "startdate", "city" };
ConditionExpression eventname1 = new ConditionExpression();
eventname1.AttributeName = "event_name";
eventname1.Operator = ConditionOperator.Equal;
eventname1.Values = new string[] { "Event A" };
ConditionExpression eventname2 = new ConditionExpression();
eventname2.AttributeName = "event_name";
eventname2.Operator = ConditionOperator.Equal;
eventname2.Values = new string[] { "Event B" };
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.Or;
filter.Conditions = new ConditionExpression[] { eventname1, eventname2 };
LinkEntity link = new LinkEntity();
link.LinkCriteria = filter;
link.LinkFromEntityName = "my_event";
link.LinkFromAttributeName = "eventid";
link.LinkToEntityName = "my_event_response";
link.LinkToAttributeName = "eventid";
QueryExpression query = new QueryExpression();
query.ColumnSet = columns;
query.EntityName = EntityName.mbs_event.ToString();
query.LinkEntities = new LinkEntity[] { link };
RetrieveMultipleRequest request = new RetrieveMultipleRequest();
request.Query = query;
return (RetrieveMultipleResponse)crmService.Execute(request);
我希望得到一些关于如何获取我需要的数据的建议。
I'm trying to build a Dynamics CRM 4 query so that I can get calendar events that are named either "Event A" or "Event B".
A QueryByAttribute doesn't seem to do the job as I cannot specify a condition where the field called "event_name" = "Event A" of "event_name" = "Event B".
When using the QueryExpression, I've found the FilterExpression applies to the Referencing Entity. I don't know if the FilterExpression can be used on the Referenced Entity at all. The example below is something like what I want to achieve, though this would return an empty result set as it will go looking in the entity called "my_event_response" for a "name" attribute. It's starting to look like I will need to run several queries to get this but this is less efficient than if I can submit it all at once.
ColumnSet columns = new ColumnSet();
columns.Attributes = new string[]{ "event_name", "eventid", "startdate", "city" };
ConditionExpression eventname1 = new ConditionExpression();
eventname1.AttributeName = "event_name";
eventname1.Operator = ConditionOperator.Equal;
eventname1.Values = new string[] { "Event A" };
ConditionExpression eventname2 = new ConditionExpression();
eventname2.AttributeName = "event_name";
eventname2.Operator = ConditionOperator.Equal;
eventname2.Values = new string[] { "Event B" };
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.Or;
filter.Conditions = new ConditionExpression[] { eventname1, eventname2 };
LinkEntity link = new LinkEntity();
link.LinkCriteria = filter;
link.LinkFromEntityName = "my_event";
link.LinkFromAttributeName = "eventid";
link.LinkToEntityName = "my_event_response";
link.LinkToAttributeName = "eventid";
QueryExpression query = new QueryExpression();
query.ColumnSet = columns;
query.EntityName = EntityName.mbs_event.ToString();
query.LinkEntities = new LinkEntity[] { link };
RetrieveMultipleRequest request = new RetrieveMultipleRequest();
request.Query = query;
return (RetrieveMultipleResponse)crmService.Execute(request);
I'd appreciate some advice on how to get the data I need.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
QueryExpression 对象有一个可以设置的 Criteria 属性。如果您正在查找名称为 A 或名称 B 的“my_event”记录,只需按如下方式设置:
如果您仅查找具有响应的事件,请保留 LinkEntity 部分,但将 FilterExpression 移至像我上面那样的 QueryExpression 对象。
The QueryExpression object has a Criteria property that you can set. If you're looking for "my_event" records that have name A or name B, just set it up like this:
If you're only looking for events that have responses, keep the LinkEntity part in, but move the FilterExpression over to the QueryExpression object like I have above.