web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

addPreSearch and not working in dynamics crm 365 V9

(0) ShareShare
ReportReport
Posted on by

Hi Guys,

I am filter Subgrid records based up on mobilephone number but it is not working. i call the function behind the mobile number field.

this is the code i wrote.

function filterSubgrid(executionContext) {

debugger;
var Sdk = window.Sdk || {};

Sdk.setParentAccountIdFilter = function (executionContext) {

// get the form context
formContext = executionContext.getFormContext();
formContext.getControl("Related_Details").addPreSearch(Sdk.filterCustomerAccounts);
}

Sdk.filterCustomerAccounts = function () {

// Only show accounts with the type 'Preferred Customer'
var customerAccountFilter = "<filter type='and'><condition attribute='new_mobilephone' operator='eq' value='828**********'/></filter>";
formContext.getControl("Related_Details").addCustomFilter(customerAccountFilter, "new_rms");

}

 


Help Me Guys..

Thank You

Dinesh

*This post is locked for comments

I have the same question (0)
  • Rawish Kumar Profile Picture
    13,758 on at

    Hi Dinesh,

    Did you debug the script in your browser to see which line is failing and what is the error.

  • DineshRaja Profile Picture
    on at

    It error shows in this line

    formContext.getControl("Related_Details").addPreSearch(Sdk.filterCustomerAccounts);

    it shows error like this .addPreSearch is not a function..

  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    Sorry just noticed. If you need to filter the subgrid records. you dont need presearch function , addpreearch is to filter lookup records and not subgrid.

    if you need to filter subgrid records - you have to use SetParameter function and pass fetch xml to it:

    community.dynamics.com/.../254441  

    joshimandarblog.wordpress.com/.../crm-2015-applying-custom-fetchxml-to-a-subgrid-using-javascript  

  • gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    Try with this , I tested in my instance below code should work.

    // Register below method onchange of the new_mobilephone field , make sure you are passing execution context
    function setParentAccountIdFilter(executionContext) { // get the form context formContext = executionContext.getFormContext(); formContext.getControl("new_Related_Details").addPreSearch( // Field Name should be with publisher name function () { filterCustomerAccounts(formContext); } ); } function filterCustomerAccounts(formContext) { // Only show accounts with the type 'Preferred Customer' var customerAccountFilter = "<filter type='and'><condition attribute='new_mobilephone' operator='eq' value='828**********'/></filter>"; formContext.getControl("new_Related_Details").addCustomFilter(customerAccountFilter); // Field Name should be with publisher name }
  • gdas Profile Picture
    50,091 Moderator on at

    "it shows error like this .addPreSearch is not a function.. " this is because field name is not correct. Should be with publisher name . Make sure this field should be lookup field.

  • DineshRaja Profile Picture
    on at

    it is not a lookupfield  goutam it is subgrid..

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hmm , I have seen later . There is no such method with name "addPreSearch" in the grid control . So you have to do unsupported way  in this case which Rawish suggested earlier.

    nishantrana.me/.../filter-subgrid-in-dynamics-365-with-new-form-rendering-or-turbo-form

    mahadeomatre.blogspot.com/.../dynamically-filter-form-sub-grid-to.html

  • DineshRaja Profile Picture
    on at

    document.getElementById is not works in D365 v9 right..instead of this what can I use

  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    dont use that -all you have to do it take the grid control. : docs.microsoft.com/.../getcontrol  

  • DineshRaja Profile Picture
    on at

    I done the code all are executed but related record does not show in the grid all records are shown.

    Here's the modified code.

    function filterSubgrid(executionContext)

    {

    var formContext = executionContext.getFormContext();

    var subgrid = formContext.getControl("new_Related_Details");

    if(subgrid == null)

    {

    setTimeout(filterSubgrid, 500);

                   return;

    }

    var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+

    "<entity name='new_rms'>"+

    "<attribute name='new_name' />"+

    "<attribute name='new_mobilephone' />"+

    "<attribute name='new_email' />"+

    "<attribute name='new_rmsid' />"+

    "<order attribute='new_name' descending='false' />"+

    "<filter type='and'>"+

    "<condition attribute='new_mobilephone' operator='eq' value='82********' />"+

    "</filter>"+

    "</entity>"+

    "</fetch>";

    if(subgrid.control != null)

    {

    subgrid.control.SetParameter("fetchXml", fetchXml);

    subgrid.control.refresh();

    }

    }

    what I made mistake in this code..help me

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Varsha deshpande Profile Picture

Varsha deshpande 5

#2
JS-09031509-0 Profile Picture

JS-09031509-0 3

#3
Ciprian  P Profile Picture

Ciprian P 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans