0

I have a requirement for which i have been stuck on for few days. I would kindly require some help on this.

So,I have 3 Lists naming List A, List B, List C.
List A acts as a master list which has all the columns along with their data.
List B has only the employee Names as people picker field. List C is where i want to fetch the data and it acts as a destination.

Now, what i want is to Get the employee name From List B and match it With names in List A and then get Project names of employees based on the names that i have fetched in List C.
I have tried getting the Data directly from List A into List C but i cannot fetch all the employee names from List A into List C.
Example : say there are 12 Employee Names in List A i am getting only 7 Names in List C.
That is why i am trying the three List Approach
Please Help if possible.
Below i am attaching my code used for fetching Names from List A into List C.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" 
  type="text/javascript"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js" 
   type="text/javascript"></script>
     <script type="text/javascript">
       $(function(){
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>");
$("input[title^='Project Name']").hide();
$("input[title^='Project Name']").after("<select id='ProjectField' class='ms-RadioText'><option value=''></option></select>");
var allEmployeeNames=getAllEmployeeNames();
console.log(allEmployeeNames)
    $.each(allEmployeeNames,function(i,employee){
    $.each(employee.Should_x0020_Cost_x0020_Modeler.results,function(j,item){
        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>");
            }           
        }   
    });         
});
$("#EmployeeField option").each(function() {
    $(this).siblings('[value="'+ $(this).val() +'"]').remove();
});
$("#EmployeeField").change(function(){
    $("input[title^='Employee Name']").val($(this).val());
    var projects=getAllProjects($(this).val());
    $("#ProjectField").html("<option value=''></option>");
    $.each(projects,function(i,project){
        $("#ProjectField").append("<option value='"+project.Project_x0020_Name+"' pdate='"+project.End_x0020_Date+"'>"+project.Project_x0020_Name+"</option>");
    });
    $("#ProjectField option").each(function() {
        $(this).siblings('[value="'+ $(this).val() +'"]').remove();
    });
}); 
$("#ProjectField").change(function(){
    $("input[title^='Project Name']").val($(this).val());
    var pDate=$(this).find("option:selected").attr("pdate");    
    $("input[title^='End Date']").val(moment(pDate).format("DD/MM/YYYY"));
});


})
          function getAllEmployeeNames(){
         var results;
        $.ajax({
       url: _spPageContextInfo.siteAbsoluteUrl + 
 "/_api/web/lists(guid'4BFF0A20-43A2-4444-881C-18932D468E54')/items $select=Should_x0020_Cost_x0020_Modeler/Title&$expand=Should_x0020_Cost_x0020_Modeler/Id&$top=2000&$filter= Title eq null",
    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;
    }
   function getAllProjects(employeeName){
var results;
$.ajax({
    url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists(guid'4BFF0A20-43A2-4444-881C-18932D468E54')/items?$select=Project_x0020_Name,End_x0020_Date,Should_x0020_Cost_x0020_Modeler/Title&$filter=Status eq 'Completed' and Should_x0020_Cost_x0020_Modeler/Title eq '"+employeeName+"'&$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;
  }

  • you messed all things together. – Negi Rox Nov 20 '18 at 6:55
  • go step by step you can achieve it easily – Negi Rox Nov 20 '18 at 6:55
  • could you help me regarding this? – jayant khushalani Nov 20 '18 at 8:46
  • yes i can is it sharepoint online? – Negi Rox Nov 20 '18 at 8:47
  • yes it is sharepoint online – jayant khushalani Nov 20 '18 at 8:47
0

Hey can you please tell your exact requirement clearly ?

If I do have a list name A, and i have 10 employee name in the employee cloum, then I do have a 2nd list named B , there I do have 7 employee name in the employee colum, And you have third list name C , where you want to fetch the matching name , is this your requirement ?

  • Actually i want to fetch the employee name from List A to List B in a dropdown. As sharePoint allows to fetch 100 items at default, i used the Top function, but i do not get all the employee names in List B. – jayant khushalani Dec 8 '18 at 16:16

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.