Hello Everyone!
I'm trying to replicated a filtered lookup behavior on "Phone Call" in the business process flow section.
I've got on the "Phone Call" 2 lookup fields as follow:
1. Service Call type (new_productfamily).
2. Service Type (new_servicetype).
A service type records holds within it the service call type value as well.
And basically, once service call type = service call type (on service type record) fetch service type value.
Once I choose a service call type I've got Service type filtered appropriately.
However, I've added those lookup to my process flow and alas the filtering doesn't take on them.
So I've snooped around and it's not possible oob and require some js.
I was looking at this script below but unable to run it.
Where/which event handler am I putting this in (onChange of the "Service Type" lookup??)
function filterLookup() {
//Check if the control exist on the form
if (Xrm.Page.getControl(“header_process_new_servicecalltype”) != null) {
// add the event handler for PreSearch Event
Xrm.Page.getControl(“header_process_new_servicecalltype”).addPreSearch(addFilter);
}
}
function addFilter() {
var sCallTypeId = null;
var sCallTypeLookup;
var fetchQuery;
try {
//Check if control exist on form
if (Xrm.Page.getControl(“header_process_new_servicecalltype”) != null && Xrm.Page.getControl(“header_process_new_servicecalltype”).getAttribute().getValue() != null) {
//Get Service Call Type lookup value
sCallTypeLookup = Xrm.Page.getControl(“header_process_new_servicecalltype”).getAttribute().getValue();
//Get the Service Call Type id
sCallTypeId = sCallTypeLookup[0].id;
}
//Build fetch
if (sCallTypeId != null || sCallTypeId != undefined) {
fetchQuery = “<filter type=’and’>” +
“<condition attribute=’new_servicetypeid’ operator=’eq’ value=’” + sCallTypeId + “‘ />” +
“</filter>”;
//add custom filter
Xrm.Page.getControl(“header_process_new_servicetype”).addCustomFilter(fetchQuery);
}
} catch (e) {
Xrm.Utility.alertDialog(“addFilter Error: ” + (e.description || e.message));
}
}
Thank you,
- Bod