0


I have a small requirement regarding People Picker Data.

What i am trying to do in the below code is to fetch data from List A into List B. There are various columns involved but the one i am facing problem with is People Picker.

I am able to fetch People-Picker Value with no issues but it only gives me 100 values in the array and the problem with that is there are duplicate values.

Thus, As the 100 items do involve names but there are few names which are missed due to the duplication.

When i am appending the Names into the dropwdown, i am removing the duplicate values but i am not able to get all the names in that column.

//To get all employees name.

function getAllEmployeeNames(){
var results;
$.ajax({
    url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('Should Cost Projects')/items?$select=Should_x0020_Cost_x0020_Modeler/Title&$expand=Should_x0020_Cost_x0020_Modeler/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;
console.log(results);
  }

// To append employee name into dropdown.

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();
    $.each(allEmployeeNames,function(i,employee){
    $.each(employee.Should_x0020_Cost_x0020_Modeler.results,function(j,item){
    console.log(employee.Should_x0020_Cost_x0020_Modeler.results);
       // if(employeeName==item.Title){
            $("#EmployeeField").append("<option selected='selected' value='"+item.Title+"'>"+item.Title+"</option>");
        /*}else{
            if(item.Title!=undefined){
                $("#EmployeeField").append("<option value='"+item.Title+"'>"+item.Title+"</option>");
                console.log("undefined");
            }           
        } */  
    });         
});

//To remove duplicate values after appending into dropdown

$("#EmployeeField option").each(function() {
    $(this).siblings('[value="'+ $(this).val() +'"]').remove();
});


Specific Requirement: I want to get all the people-picker names not only 100 names from List A.

Would really appreciate if you could help me on this.

0

As you are using rest and you are not specifying the top operator to get the number of rows to return by the get request therefore the rest api is default row as 100. To fetch more than 100 rows in a get request of rest you can use the Top =1000 Example :-

url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('Should Cost Projects')/items?$select=Should_x0020_Cost_x0020_Modeler/Title&$expand=Should_x0020_Cost_x0020_Modeler/Id&$top 5",

Note:-

  1. $top — It is used to control the page size. We can use $top to get more than 100 items but there is also limitation that you cannot get more than 5000 items using $top

.

0

By default REST GET method returns only 100 items.

To get more items than 100, you need to use "$top" functionality in REST endpoints.

In your case, while fetching items from list A, use following URL:

_spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('Should Cost Projects')/items?$select=Should_x0020_Cost_x0020_Modeler/Title&$expand=Should_x0020_Cost_x0020_Modeler/Id&$top=1000"

it will pull 1000 items from list A.

  • As i tried your method and i am receiving names in the array but it seems that duplicate values are also coming which i have a code for written in the example above but it is not working for it. Any help regarding it? – jayant khushalani Oct 23 '18 at 6:23
  • there are various ways to remove duplicates, in your case i will suggest that remove duplicate values before appending to dropdown. see some examples given here to remove duplicates. – Ganesh Sanap Oct 23 '18 at 6:52
  • If this answers your requirement, please accept the answer so that other user can get help from accepted answers directly. – Ganesh Sanap Oct 27 '18 at 17:28
  • The problem is i am not able to achieve all the names. – jayant khushalani Oct 28 '18 at 15:01

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.