Hi All,
I have implemented a piece of javascript code in order to be able to filter one lookup based on other lookup on the business process flow.
So, when the user select the Account name on Account Lookup, then on the contact lookup will be available all the contacts related to that account.
On a creation of a new record, it works fine. The problem is if you pick an existing record and try to change the contact, it will throw an error message (please see the image below):
This issue only happens after save the record or open an existing one.
I have attached the script on onLoad on the form, then after saw the error tried to add same function on the onChange of the contact field, and the result is the same.
In below you can find the script that i have used:
function filterLookup() {
//Check if the control exist on the form
if (Xrm.Page.getControl("header_process_contact") != null) {
// alert("found header_process_contact!");
// add the event handler for PreSearch Event
Xrm.Page.getControl("header_process_contact").addPreSearch(addFilter);
}
}
function addFilter() {
var accountId = null;
var accountLookup;
var fetchQuery;
try {
//Check if control exist on form
if (Xrm.Page.getControl("header_process_customerid") != null && Xrm.Page.getControl("header_process_customerid").getAttribute().getValue() != null) {
//Get Account lookup value
// alert("start getting lookup value");
accountLookup = Xrm.Page.getControl("header_process_customerid").getAttribute().getValue();
//Get the account id
accountId = accountLookup[0].id;
// alert("accountid: " + accountId);
}
//Build fetch
if (accountId != null || accountId != undefined) {
fetchQuery = "<filter type='and'>" +
"<condition attribute='statecode' operator='eq' value='0' />" +
"<condition attribute='parentcustomerid' operator='eq' value='" + accountId + "' />" +
"</filter>";
// alert("fetchquery: " + fetchQuery);
//add custom filter
Xrm.Page.getControl("header_process_contact").addCustomFilter(fetchQuery);
}
} catch (e) {
Xrm.Utility.alertDialog("addFilter Error: " + (e.description || e.message));
}
}
Can you please advice where this is hitting?
Thank You in advance.
RR










