Skip to main content

Notifications

Announcements

No record found.

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

  • Prashnat Verma Profile Picture
    Prashnat Verma 287 on at
    RE: addCustomFilter error "Xrm.Page.getAttribute(...).addCustomFilter is not a function"

    Hi,

    See the link below.

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

    thanks

  • Vaibhav Jaiswal Profile Picture
    Vaibhav Jaiswal 100 on at
    RE: addCustomFilter error "Xrm.Page.getAttribute(...).addCustomFilter is not a function"

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

  • Suggested answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: addCustomFilter error "Xrm.Page.getAttribute(...).addCustomFilter is not a function"

    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
    Vaibhav Jaiswal 100 on at
    RE: addCustomFilter error "Xrm.Page.getAttribute(...).addCustomFilter is not a function"

    Thanks Rawish . The error is not coming now.

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

  • Temmy Wahyu Raharjo Profile Picture
    Temmy Wahyu Raharjo 2,914 on at
    RE: addCustomFilter error "Xrm.Page.getAttribute(...).addCustomFilter is not a function"

    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.

  • Verified answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: addCustomFilter error "Xrm.Page.getAttribute(...).addCustomFilter is not a function"

    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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans