D365 V9{Upgrade}: “v_5 is not a function” error while adding custom filter to lookup

Recently, after upgrading our one of the D365 instance to V9, we came across an issue with custom filtering of lookup.

We were using below piece of code snippet to add custom filter:


if (formContext.getControl("sab_lnepackageid") != null) {

formContext.getControl("sab_lnepackageid").addPreSearch(addFilterOpp(executionContext));

}

and below is the definition of the addFilterOpp method:

function addFilterOpp(executionContext) {
var formContext = executionContext.getFormContext();

var brandId = null;
var brandLookup;
var enquiry;
var fetchQuery;
try {
//Check if control exist on form
if (formContext.getControl("sab_brandid") != null && formContext.getControl("sab_brandid").getAttribute().getValue() != null
&& formContext.getControl("sab_eventtype") != null && formContext.getControl("sab_eventtype").getAttribute().getValue() != null) {

brandLookup = formContext.getControl("sab_brandid").getAttribute().getValue();
brandId = brandLookup[0].id;

enquiry = formContext.getControl("sab_eventtype").getAttribute().getValue();

}
//Build fetch
if ((brandId != null || brandId != undefined) && (enquiry != null || enquiry != undefined)) {
 fetchQuery = ""

formContext.getControl("sab_lnepackageid").addCustomFilter(fetchQuery);
}
} catch (e) {
Xrm.Navigation.openAlertDialog("addFilter Error: " + (e.description || e.message));
}
}

fetchQuery = “<filter type=’and’>” +

“<condition attribute=’sab_brandid’ operator=’eq’ value='” + brandId + “‘ />” +
“<condition attribute=’sab_eventtype’ operator=’eq’ value='” + enquiry + “‘ />” +
“</filter>”;

However, the lookup was not working when we were clicking on magnifying glass of lookup. Checking the Developer Tools –> Console, we found the error message “v_5 is not a function and blah blah..”.

To fix this issue, we changed the code where we were passing execution context.

Below is the updated code snippet in which we removed execution context from the parameter and passed only the name of the method:


if (formContext.getControl("sab_lnepackageid") != null) {

formContext.getControl("sab_lnepackageid").addPreSearch(addFilterOpp);

}

and there was no change to the definition of the function addFilterOpp:


function addFilterOpp(executionContext) {
var formContext = executionContext.getFormContext();

var brandId = null;
var brandLookup;
var enquiry;
var fetchQuery;
try {
//Check if control exist on form
if (formContext.getControl("sab_brandid") != null && formContext.getControl("sab_brandid").getAttribute().getValue() != null
&& formContext.getControl("sab_eventtype") != null && formContext.getControl("sab_eventtype").getAttribute().getValue() != null) {

brandLookup = formContext.getControl("sab_brandid").getAttribute().getValue();
brandId = brandLookup[0].id;

enquiry = formContext.getControl("sab_eventtype").getAttribute().getValue();

}
//Build fetch
if ((brandId != null || brandId != undefined) && (enquiry != null || enquiry != undefined)) {
 fetchQuery =""

formContext.getControl("sab_lnepackageid").addCustomFilter(fetchQuery);
}
} catch (e) {
Xrm.Navigation.openAlertDialog("addFilter Error: " + (e.description || e.message));
}
}

fetchQuery = “<filter type=’and’>” +

“<condition attribute=’sab_brandid’ operator=’eq’ value='” + brandId + “‘ />” +
“<condition attribute=’sab_eventtype’ operator=’eq’ value='” + enquiry + “‘ />” +
“</filter>”;

After making the above change the custom filter started working on lookup.

5.png

NOTE: This change is working on only Chrome and IE browsers. On Firefox, it’s still not working.

Hope it helps !!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.