1

I am using below JS code to hide/remove duplicate values from a lookup column.

<script language="javascript" type="text/javascript" 
src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
var previousOption;

$(document).ready(function() {
$('#Vendor_x0020_name').parent().next().find('select option').each(function() {
    if (this.text == previousOption) $(this).remove();
    previousOption= this.text;
});
});
</script>

The lookup column name is: Vendor Name and it has some duplicate values showing up in the drop-down. The same code works when added on the New item form in SPOnline list but doesn't work when added to new item form of SharePoint server 2013 list.

Can someone help,thanks.

0

This works for me:

<script language="javascript" type="text/javascript" 
src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
var previousOption;

$(document).ready(function() {
$("td[id^='Vendor_x0020_name']").parent().next().find('select option').each(function() {
    if (this.text == previousOption) $(this).remove();
    previousOption= this.text;
});
});
</script>
0

We can use the code below to achieve it.

<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
var previousOptions={};
$(function() {
    $("select[title='Vendor Name'] option").each(function() {
        if (previousOptions[this.text]){
            $(this).remove();
        }else {
            previousOptions[this.text] = this.value;
        }        
    });
});
</script>

enter image description here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.