none
Get unique values from sharepoint list in drop down

    Question

  •              function getEmpList()
                {
                    $.ajax({
                        url: siteurl + "/_api/web/lists/getbytitle('TestEmpInfo')/items?$select=Id,EmpName",
                        method: "GET",
                        headers: { "Accept": "application/json; odata=verbose" },
                        success: function (data) {
                            empList.push(data.d.results);
                            console.log(empList);
                            var uniqueEmpList = GetUnique(empList);
                            console.log(uniqueEmpList);
                            for(i=0;i<data.d.results.length;i++)
                            {
                                $('#totalEmpList').append($("<option/>").val(uniqueEmpList[i].Id).text(uniqueEmpList[i].EmpName)); 
                            }     

                        },
                        error: function (data) {
                            alert("Error: "+ data);
                        }                
                    });
                }

    Please help me with this
    I have to get uniques values of shrepoint list to a dropdown

    Thanks in advance 

                           
    Friday, January 11, 2019 8:45 AM

All replies

  • Here you go

    http://mahedevelopment.blogspot.com/2015/09/sharepoint-2013-get-distinct-values-of.html

    http://shlok-sharepoint.blogspot.com/2012/01/select-distinct-or-unique-values-from.html


    Please remember to click Mark as Answer on the answer if it helps you

    Friday, January 11, 2019 7:31 PM
  • Hi,

    As you have retrieved the list item json data, you could try below function to get distinct value also.

    var lookup = {};
    var items = json.DATA;
    var result = [];
    
    for (var item, i = 0; item = items[i++];) {
      var name = item.name;
    
      if (!(name in lookup)) {
        lookup[name] = 1;
        result.push(name);
      }
    }

    Here is the thread for your reference.

    https://stackoverflow.com/questions/17780508/selecting-distinct-values-from-a-json

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, January 14, 2019 4:19 AM
  • Why do you need to filter unique on Client Side Script?

    Why not fix the data so it will only allow unique Employees?

    It seems you are getting a list of Employees from a certain list based on your code. How can there be multiple instances of an Employee on this List?

    If you really need to filter unique Employees based on the list, how to tell one from the other, EmpName and SharePoint ID is not enough, you should have separate Employee ID for example, unless column is People Picker so you should have a lookup ID.


    Artificial intelligence can never beat natural stupidity.

    Tuesday, January 15, 2019 8:44 AM
  • because single employee may consists of multiple teams thats why
    Tuesday, January 15, 2019 11:20 AM
  • Hi,

    Have you tried above suggested solutions?

    You could post the issue you got when you testing the solutions.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, January 16, 2019 3:49 AM