Advanced Find - combine related entitie with OR

流过昼夜 提交于 2019-12-10 03:31:36

问题


Is there any way to create that query?

I need data from Adress and Contact Adress, normally i can just combine them by Combine OR but not in this case.

I guess that i must write new plugin with PreExecute() method, get my query, parse data and then manualy get equal address OR there are other way?


回答1:


I am unaware of any way to do the above.

Rather than write a plugin however I would do a report.

Simplest way I can think of is to do your fetchXML without filters like so.

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
  <entity name="account">
    <attribute name="name" />
    <attribute name="primarycontactid" />
    <attribute name="telephone1" />
    <attribute name="accountid" />
    <attribute name="address1_city" />
    <order attribute="name" descending="false" />
    <link-entity name="contact" from="parentcustomerid" to="accountid" alias="ac">
        <attribute name="address1_city" />
    </link-entity>
  </entity>
</fetch>

Then toggle visibilty of rows in your report using

=Fields!address1_city.Value="Sydney" Or Fields!ac_address1_city.Value="Sydney"

Obviously you could replace Sydney with a Parameter




回答2:


I solved the problem.

  • Create Plugin for pre-validation with Execute() method and some method for data parsing.
  • In entity view add some field with GUID.
  • If plugin found guid in your view, it 'll get fetchxml query for your entity and second query entity else 'll show default view.
  • Parse data for what you want show for user.
  • Register your plugin.
  • Profit.

PS I'll add sources in day or two after refactoring and approval from customer.

Edit:

First of all - y need create new GUID and add string field to view with that guid to view(It is better to hide it from the user). Create plugin with RetrieveMultiple action and Post validation(in Pre action you may lose your changes)

In plugin: main method RetrieveMultiple which will get context and service from wich you will take query, then you need get fetchXml and check if there are your GUID.

            string fetchXml = string.Empty;
            var query = context.InputParameters["Query"] as QueryExpression;
            var fetchQuery = context.InputParameters["Query"] as FetchExpression;

                if (query == null)
                {
                    if (fetchQuery == null)
                    {
                    return;
                    }
               fetchXml = fetchQuery.Query;
                }

                // Convert query to a fetch expression for processing and apply filter
                else
                {
                    fetchXml =
                        ((QueryExpressionToFetchXmlResponse)
                            service.Execute(new QueryExpressionToFetchXmlRequest {Query = query})).FetchXml;
                }

                if (fetchXml.Contains(OpportunityFilterGuid))
            {
                    ApplyFilter(context, service, query);
                }
            }

In your ApllyFilter method you need:

  1. Get query from user(he can add some new fileds).

  2. Delete your field with GUID.

  3. Execute query.

  4. Delete fileds, that can conflict with your OR statement.

  5. Add link-entity to query.

  6. Execute query.

  7. Add received entities from second query to first.

  8. Using LINQ select entities wich are not repeated.

     collectionOne.Entities.GroupBy(oppId => oppId.Id).Select(opp => opp.First())
    
  9. Send that data to client.




回答3:


Put simply, there is no way to do what you are asking through advanced find.

The example query you put up will only show you Accounts where associated Contacts have the address match (as well as obviously the Account having the address match). Once you associate another entity in an Advanced Find, you will only see parents with the associated records - there is no ability to do (what is effectively) an outer join.

Your only options are really to build something in Silverlight or HTML and add it as a web-resource - once inside that code you can pretty much display anything you want. As others have suggested, this is possible in a report.



来源:https://stackoverflow.com/questions/17995575/advanced-find-combine-related-entitie-with-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!