Dynamic CRM 2013 Learning Notes (eight) filter lookup controls (similar to provincial and municipal linkage)

Source: Internet
Author: User

We often want to implement similar provinces and cities, the same function, the common is two search control, one selected the province, the other city's search control is automatically filtered, only show the current save the city, not all the city. Of course, this is the simplest, and there are more complex functions in the actual work to be implemented by filtering the lookup controls. This article mainly introduces the basic search control filtering, the complex filtering of multi-table associations, and the filtering of the sub table to implement the lookup control.

First, simple filter

First look at the requirements:

Press "Special GL Indicator" to filter Posting

The lookup control adds the Presearch event. It occurs before the Lookup control displays a dialog box for the user to find the record, and unlike other events, the interface cannot be used to set the code that executes when the event occurs. Only through Xrm.Page.getControl (ARG). Addpresearch (handler) and Xrm.Page.getControl (ARG). Removepresearch (Handler) To add or clear execution code for the event.

The implementation method is simple, in the OnLoad event of the form plus prefilterlookup

 
 1: function  prefilterlookup () {
 2:xrm.page.getcontrol (" new_postingid  "). Addpresearch (function  () {
 3:addpostinglookupfilter (); 
 4:}); 
 5:} 
  function Addpostinglookupfilter () {
  2:     var gl = Xrm.Page.getAttribute ("new_special_gl_indicatorid"). GetValue ();
  3:     var fetchXml = "";
  4:     ifnull) {
  5:         fetchXml = "<filter type= ' and ' ><condition attribute= ' new_special_gl_indicatorid ' operator= ' eq ' Value= '"+ gl[0].id +"'/></filter>";
  6:     }
  7:     Else {
  8:         fetchXml = "<filter type= ' and ' ><condition attribute= ' new_special_gl_indicatorid ' operator= ' null '/></filter>';
  9:     }
Ten:     Xrm.Page.getControl ("new_postingid"). Addcustomfilter (FETCHXML);
11:}

First, add the Addpresearch method to the lookup control you want to filter, and use Addcustomfilter to control it.

Second, the complex filtration

Above we implemented a simple filter, below we implement a complex point of filtering. The above used is addcustomfilter, that is, filter, if the relationship complex point, there are multiple related tables, filter can not be achieved, then it is necessary to use the Addcustomview.

For example, first filter by "Company Code", and then press "Company tax Procedure" (not shown on the page) to filter tax Code.

First, add a new method Taxcodecustomview to the form onload event, which is implemented as follows:

  function Taxcodecustomview () {
  2:     var company = Xrm.Page.getAttribute ("new_company_codeid"). GetValue ();
  3:     var viewId = "{00000000-0000-0000-0000-000000000001}";
  4:     var viewdisplayname = "";
  5:     var fetchXml = "<fetch mapping= ' logical ' >" +
  6:       "<entity name= ' new_taxprocedure_taxcode ' >" +
  7:             "<attribute name= ' New_taxprocedure_taxcodeid '/>" +
  8:             "<link-entity name= ' new_company_taxprocedure ' to= ' new_tax_procedure ' from= ' new_name ' alias= ' NCB ' Link-type= ' inner ' >';
  9:     ifnull) {
Ten:         fetchXml + = "<filter><condition attribute= ' New_companyid ' operator= ' eq ' value= '" + company[ 0].id + "'/></filter>";
One:     }
:     fetchXml + = "</link-entity>" +
:       "</entity>" +
:     "</fetch>";
:     var layoutxml = "<grid name= ' resultSet ' object= ' 10024 ' jump= ' new_name ' select= ' 1 ' icon= ' 1 ' preview= ' 1 ' >' +
:         "<row name= ' result ' id= ' New_taxprocedure_taxcodeid ' >" +
:             "<cell name= ' new_tax_procedure ' width= '/>" +
:             "<cell name= ' new_name ' width= '/>" +
:         "</row></grid>";
:     Xrm.Page.getControl ("new_tax_codeid"). Addcustomview (ViewId, "new_taxprocedure_taxcode true);
23:}

Here is the use of Addcustomview with FetchXML to achieve complex correlation filtering.

Third, the sub-table with the Main table field to filter

Is the child table, also has the posting and the tax Code, also wants to filter like the main table, but the child table does not want to filter the field "Special GL Indicator", "Company Code"

Of course we can use OData to query these two values on the main table through the main table ID, and then filter, but this is inefficient and the code above is not reusable.

You can then create a new 1:n relationship from the main table to mapping the two fields on the main table we need onto the child table.

Add these two fields to the sub-table, but don't show them.

This allows you to reuse the main table's JS code in the Sub-table, and just add prefilterlookup on the form onload event.

Dynamic CRM 2013 Learning Notes Series Rollup

Dynamic CRM 2013 Learning Notes (eight) filtering lookup controls (similar to provincial and municipal linkage)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.