Skip to main content

Function: MnOnPreSearch

MnOnPreSearch(controlName): (target: any, key: any, descriptor: PropertyDescriptor) => void

Decorator that marks a method as an event handler for pre-search event.

This event is fired when a lookup column search is executed. It allows to modify the search query by adding filters.

Remarks

Available on pages: Record only.

Registration: Automatic registration at runtime.

For more information, see Microsoft Client API Reference

Example

Filter a multi-lookup of type customer (specific D365 lookup type) to only allow accounts and disable the search of contacts.

@MnComponent({
scope: {
pageType: "record"
}
})
export class AccountOnlyInCustomerLookupComponent {
@MnInput()
input: {
customerLookup: string;
}

@MnConfig(i => i)
config: {
customerLookup: string
}

@MnOnPreSearch(c => c.config.customerLookup)
disallowContactSearch(eventArg: FormEventArg) {
const customerCtrl = eventArg.formCtx.getControl<Xrm.Controls.LookupControl>('customer');
customerCtrl.addCustomFilter('<filter type="and"><condition attribute="contactid" operator="null"/></filter>', 'contact');
}
}

Parameters

NameTypeDescription
controlNameValueOrConfigPropertyMapper<string>Name of the lookup control or callback function that returns the name of the lookup control from the component configuration.

Returns

fn

▸ (target, key, descriptor): void

Parameters
NameType
targetany
keyany
descriptorPropertyDescriptor
Returns

void

Defined in

packages/core/src/core/metadata/events.ts:567