Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advanced Find - combine related entitie with OR

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?

like image 991
Maks Martynov Avatar asked Aug 01 '13 13:08

Maks Martynov


2 Answers

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

like image 175
Campey Avatar answered Nov 10 '22 18:11

Campey


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.

like image 27
Maks Martynov Avatar answered Nov 10 '22 17:11

Maks Martynov