Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

addPreSearch and not working in dynamics crm 365 V9

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

  • Verified answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: addPreSearch and not working in dynamics crm 365 V9

    I have seen people using and it works but doesnt come under "supported methods".

    People have suggested that its better and future proof if you use a plugin instead.

    community.dynamics.com/.../236817  

    stackoverflow.com/.../how-to-apply-custom-fetchxml-to-a-subgrid-using-javascript  

    Meanwhile i will try the above script in my d365 trial.

  • DineshRaja Profile Picture
    DineshRaja on at
    RE: addPreSearch and not working in dynamics crm 365 V9

    for privacy..and I want to know either setparameter is work in dynamics 365 v9

  • Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: addPreSearch and not working in dynamics crm 365 V9

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

    this line - are you hiding the phone number in the community for the sake of privacy or in the code itself you have  put value like this?

  • DineshRaja Profile Picture
    DineshRaja on at
    RE: addPreSearch and not working in dynamics crm 365 V9

    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

  • Suggested answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: addPreSearch and not working in dynamics crm 365 V9

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

  • DineshRaja Profile Picture
    DineshRaja on at
    RE: addPreSearch and not working in dynamics crm 365 V9

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

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: addPreSearch and not working in dynamics crm 365 V9

    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
    DineshRaja on at
    RE: addPreSearch and not working in dynamics crm 365 V9

    it is not a lookupfield  goutam it is subgrid..

  • gdas Profile Picture
    gdas 50,085 on at
    RE: addPreSearch and not working in dynamics crm 365 V9

    "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.

  • gdas Profile Picture
    gdas 50,085 on at
    RE: addPreSearch and not working in dynamics crm 365 V9

    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 }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans