Team,
We have implemented following code for custom lookup field and it is working fine. But it needs 3 clicks.
- Click the search icon in the lookup field
- Select “Look up More Records”
- Remove the selected value in the Search textbox
- Then it is showing the filtered records
But I have seen many article and it is showing the filtered records with one click when user click the search icon. I don’t know why it is not working for me.
Really appreciate your help.
CGC.ImportedElements.Form.OnLoad = function (arg) {
Xrm.Page.getControl("cel_payperiod").addPreSearch(CGC.ImportedElements.Form.AddLookupFilter);
}
CGC.ImportedElements.Form.AddLookupFilter = function (arg) {
var control = arg.getEventSource();
var controlName = control.getAttributeName();
var xml = "";
var recordId = Xrm.Page.data.entity.attributes.get(controlName).getValue()[0].id;
var entityName = Xrm.Page.data.entity.attributes.get(controlName).getValue()[0].entityType;
var payrollId = null;
SDK.WEBAPI.retrieveRecordSync(recordId,
entityName,
"_cel_payroll_value",
null,
function (response) {
if (response != null) {
payrollId = response._cel_payroll_value;
} else {
Xrm.Page.ui.setFormNotification("Failed to filter & etc... ", "EROR");
Xrm.Utility.alertDialog("Failed to filter & etc... ");
}
},
function (error) {
Xrm.Page.ui.setFormNotification(error.message, "EROR");
Xrm.Utility.alertDialog(error.message);
});
xml = "<filter type='and'><condition attribute='cel_payroll' operator='eq' value='" + payrollId + "' /></filter>";
Xrm.Page.getControl(controlName).addCustomFilter(xml);
};
*This post is locked for comments