Get all column values based on a distinct column value from SharePoint list through rest api and json filters

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$( document ).ready(function() {

CreateNew();
});

function CreateNew() {
    var listName = "UserProfile";
        $.ajax({
        url:_spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items?$select=Location,UserTitle,PageAccessed",
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
        },
        success: function (data) {
            //alert(JSON.stringify(data.d.results));
            var lookup = {};
var items = data.d.results;
//var result = [];
var divhtml='<ul>';
for (var item, i = 0; item = items[i++];) {
 var name = item.UserTitle;
var divLOChtml='<ul>';
 if (!(name in lookup)) {
   lookup[name] = 1;
 var loc=$.grep(data.d.results, function (element, index) {
    return element.UserTitle == name;
});
debugger;
    for (var UserLoc, j = 0; UserLoc= loc[j++];) {
    var location = UserLoc.Location;
    divLOChtml=divLOChtml+'<li>'+location +'</li>'+'<li>'+UserLoc.PageAccessed+'</li>';
    }
    divLOChtml=divLOChtml+'</ul>';
    divhtml=divhtml+'<li>'+name+divLOChtml+'</li>';
 }
}
divhtml=divhtml+'</ul>';
$('#divName').html(divhtml);
        },
        error: function (error) {
            alert(JSON.stringify(error));
        }
    });}
</script>

<div id ='divName'>
<div>

Comments

Popular posts from this blog

Add attachment filed column in SharePoint custom list forms through SharePoint designer 2013

Sharepoint 2013 interview Questions..