0

I have a small requirement where in i have a People Picker Field in List A.

Now i have a Look-up column in List B.

How do i get the People Picker Unique Values in Look-up Column.

Example

Employee Name(People Picker) in List A
Jayant
Vishal
Ashwini
Jayant
Vishal

Employee Name(Lookup Column) in List B
Jayant
Vishal
Ashwini

How can i achieve this without workflow?

0

The "Person or Group" column is not supported as a lookup in another list.

The only way to achieve this is by workflow.

Reference: People Picker Lookup column

  • There must be a way to auto populate through CSOMS. Do you have answer to that? – jayant khushalani Oct 5 '18 at 12:11
  • One more question, is it possible to get people picker data and appending it in choice field? – jayant khushalani Oct 5 '18 at 12:39
  • The people picker textbox itself is of searchable choice type. So you can just use SharePoint people picker box. Refer – Sohail Shaikh Oct 6 '18 at 7:22
0

As a workaround, we can use jQuery with REST API to achieve it. Use a single line of text field to instead of lookup field, and using REST API and jQuery to get all the Employee Names from List A, and hide this text field add a drop down control in the list form. The following example for your reference.

1.Create a custom list "List A", and create a user field "Employee Name".

2.Create a custom list "List B", and create a single line of text field "Employee Name".

3.Add the following code into a script editor web part into New/Edit form page in List B.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
    var listId="6C9991B2-50A4-4755-9E4B-9D391C2774FE";
    var employeeName=$("input[title^='Employee Name']").val();
    $("input[title^='Employee Name']").hide();
    $("input[title^='Employee Name']").after("<select id='EmployeeField' class='ms-RadioText'><option value=''></option></select>");
    var allEmployeeNames=getAllEmployeeNames(listId);
    $.each(allEmployeeNames,function(i,employee){
        if(employeeName==employee.Employee_x0020_Name.Title){
            $("#EmployeeField").append("<option selected='selected' value='"+employee.Employee_x0020_Name.Title+"'>"+employee.Employee_x0020_Name.Title+"</option>");
        }else{
            $("#EmployeeField").append("<option value='"+employee.Employee_x0020_Name.Title+"'>"+employee.Employee_x0020_Name.Title+"</option>");
        }       
    });
    $("#EmployeeField").change(function(){
        $("input[title^='Employee Name']").val($(this).val());
    });
})
function getAllEmployeeNames(listId){
    var results;
    $.ajax({
        url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists(guid'"+listId+"')/items?$select=Employee_x0020_Name/Title&$expand=Employee_x0020_Name/Id",
        type: "GET",
        async:false,
        headers: {
            "Accept": "application/json;odata=verbose",
        },
        success: function (data) {
            if(data.d.results.length>0){
                results=data.d.results;
            }
        },
        error: function (data) {
            //alert("Error");
        }
    });
    return results;
}
</script>
  • Hi LZ_MSFT, I tried your method, the employee name field in list b chages to Dropdown but there are no values being populated in the dropdown, Please help me with this. – jayant khushalani Oct 8 '18 at 4:56
  • Check if the list name is "List A" and check the "Employee Name" field internal name of the list A. – LZ_MSFT Oct 8 '18 at 4:59
  • i did both of them. One query, getbytitle function involves list name or internal list name? – jayant khushalani Oct 8 '18 at 5:00
  • Hi LZ_MSFT , i am not able to go into the success function as it directly goes into the error part and throws an error and also the result variable returns undefined. – jayant khushalani Oct 8 '18 at 5:18
  • Access the URL "yoursite/_api/web/lists/getbytitle('List A')/items" in browser to check if it works. My test environment is SharePoint 2013/Online, did you use SharePoint 2010? – LZ_MSFT Oct 8 '18 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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