Hide certain Lookup Values from appearing on New or Edit forms

I’ve recently had an issue where there are over 2,000 items in a lookup and trying to search for the one you want was a huge pain, the code below can find certain text in the lookup options and exclude these, doing so reduces the amount of values you see and more user friendly for the end users.

From the script below, ‘Electronic Device’ was my column name, which also was a required field. The term I was looking for was “OLD” (as old devices were no longer required and therefore flagged old).

Remember to download the JQuery CDN.

<script type=”text/javascript” src=”https://TENANT.sharepoint.com/sites/YourSharePointSiteCol/SiteAssets/CDN/jquery-3.3.1.min.js”></script>
<script>

$(document).ready(function(){
$(“select[Title=’Electronic Device Required Field’]”).find(‘option:contains(“OLD”)’).remove();
});

</script>