문제

I am using below code to remove duplicate values from a lookup column called Project Name and for some reason its not working, can someone please help me correct it.

FYI, i have already enforced unique values for the lookup column but it does not seem to do the job.

Below is the code:

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

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

This is the ID i get to see: Company_x0020_Name Below is the screenshot of the form: enter image description here

도움이 되었습니까?

해결책

A couple of things to check:

  • Your code only removes duplicates when they occur one after another, not separately.
  • Check you jquery selector. Check the html of the page and see if you are selecting the select element correctly. You need the internal name of the field. Assuming it is the same as the display name you will need the following change:

>

<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() {
$('#Project_x0020_Name').parent().next().find('select option').each(function() {
    if (this.text == previousOption) $(this).remove();
    previousOption= this.text;
});
});
</script>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top