Advanced Find - combine related entitie with OR

2019-04-24 02:08发布

Is there any way to create that query?

enter image description here

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?

3条回答
疯言疯语
2楼-- · 2019-04-24 02:50

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

查看更多
闹够了就滚
3楼-- · 2019-04-24 03:00

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.

查看更多
SAY GOODBYE
4楼-- · 2019-04-24 03:12

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.

查看更多
登录 后发表回答