addPreSearch (Client API reference)
Applies changes to lookups based on values current just as the user is about to view results for the lookup.
Lookup
formContext.getControl(arg).addPreSearch(myFunction)
Name | Type | Required | Description |
---|---|---|---|
myFunction |
Function | Yes | The function that is run just before the search to provide results for a lookup occurs. You can use this function to call one of the other lookup control functions and improve the results to be displayed in the lookup. The execution context is automatically passed as the first parameter to this function. |
In the following example, the onLoad
function is set for the form onload event. It modifies the search filter for all the lookup controls associated with the primaryid
lookup attribute because there may be more than one.
It adds the myPreSearchCallBack
function using the addPreSearch
method. This example requires all the contact records returned to have the firstname
value of 'Eric'.
function onLoad(executionContext) {
var formContext = executionContext.getFormContext()
var attribute = formContext.getAttribute("primarycontactid")
attribute.controls.forEach(control => control.addPreSearch(myPreSearchCallBack))
}
function myPreSearchCallBack(executionContext) {
var control = executionContext.getEventSource();
var filter = "<filter><condition attribute='firstname' operator='eq' value='Eric' /></filter>";
control.addCustomFilter(filter);
}