Recently in my current project there was a Lookup field as per requirement of client. I had to implement Pre-Filter on it on the basis of another option set field value.
I thought of writing this function for implementing Pre-Filter on Lookup field.
Step 1- Get the schema name and field name of Target field where to implement Pre-Filter and schema name and field name of Source field.
Step 2- Create Function-

Step 3- Copy and paste the function into Form.js in CRM which is called on form load in CRM.
Step 4- Click on OK and then Save and Publish