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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

addCustomFilter error "Xrm.Page.getAttribute(...).addCustomFilter is not a function"

(0) ShareShare
ReportReport
Posted on by 100

Hi All ,

I was trying to filter account name lookup based on the address1_city field value change on contact form using the below code . 

function filterAccountLookup() {

    try {
 
        if (Xrm.Page.getControl("address1_city") != null && Xrm.Page.getControl("address1_city") != undefined)
        {
 
            Xrm.Page.getControl("parentcustomerid").addPreSearch(function () {
                addCustomLookupfilter();
 
            });
        }
 
 
    } catch (e) {
 
        throw new Error(e.message);
 
    }
}
 
function addCustomLookupfilter() {
 
    try{
        var city = Xrm.Page.getAttribute("address1_city").getValue();
        if (city != null && city != undefined)
        {
            fetchxml = "<filter type='and'>" + "<condtion attribute='address1_city' operator='eq' value = '" + city + "' />" + "</filter>";
            Xrm.Page.getAttribute("parentcustomerid").addCustomFilter(fetchxml, "account" );
        }
    }
    catch (e)
    {
        throw new Error(e.message);
    }
    
}



But i was getting error "Xrm.Page.getAttribute(...).addCustomFilter is not a function"

 in  function addCustomLookupfilter() at line 

Xrm.Page.getAttribute("parentcustomerid").addCustomFilter(fetchxml, "account" );


Kindly help on this.

*This post is locked for comments

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

    Hi Vaibhav,

    you have to use it like the below :

    Xrm.Page.getControl("parentcustomerid").addCustomFilter(fetchxml, "account");

    getAttribute will not have addCustomerFilter function and hence you see this error.

  • Temmy Wahyu Raharjo Profile Picture
    2,916 on at

    Hi! Just minor error on your code. Should be getControl but you used getAttribute instead.

    function AddPreSearch(){
    	var run;
    	var fnSearch = function(){
    		var city = Xrm.Page.getAttribute("address1_city").getValue();
    		if(!city) return;
    		
    		var fetchXml = "<filter type='and'>" + "<condtion attribute='address1_city' operator='eq' value = '" + city + "' />" + "</filter>";
    		ctrl.addCustomFilter(fetchXml);
    	};
    		
    	return function(){
    		if(!run){
    			var ctrl = Xrm.Page.getControl("parentcustomerid");
    			if(!ctrl) return;
    			ctrl.addPreSearch(fnFilterProperty);
    			run = true;
    		}
    	}();
    }


    This one is better solution. With addPresearch actually you only need this function register on Form On Load. When lookup populate, the fnSearch will run and add condition to the data. You don't need to register on change function. Just call this function onLoad and let the API works.

    Let me know if you have question.

  • Vaibhav Jaiswal Profile Picture
    100 on at

    Thanks Rawish . The error is not coming now.

    Just for the information , how could we check such type of error about any other function.

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

    Hi Vaibhav,

    glad it worked. To answer your question , i wouldnt say there is any direct method of knowing this:

    1. go through all XRM functions that are available : msdn.microsoft.com/.../gg328474.aspx

    2. as always debugging - you will know what is breaking exactly where.

  • Vaibhav Jaiswal Profile Picture
    100 on at

    Thanks Temmy for the help... I will try this code also and check.

  • Prashnat Verma Profile Picture
    287 on at

    Hi,

    See the link below.

    www.inogic.com/.../apply-custom-filter-on-lookup-field-in-dynamic-crm-using-script

    thanks

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans