Thursday 20 February 2014

How to Get Login Name and Display Name using SharePoint 2013 REST API

jQuery.ajax({
    url: "/SiteName/_api/web/lists/getbytitle('ListName')/items",
    type: "GET",
    headers: { "Accept": "application/json;odata=verbose" },
    success: function(data, textStatus, xhr) {
        var dataResults = data.d.results;
        var resultId = dataResults[0].AuthorId.results[0];        
        getUser(resultId)
    },
    error: function(xhr, textStatus, errorThrown) {
        alert("error:"+JSON.stringify(xhr));
    }
});

function getUser(id){
var returnValue;
  jQuery.ajax({
   url: "http://YourSite/_api/Web/GetUserById(" + id + ")",
   type: "GET",
   headers: { "Accept": "application/json;odata=verbose" },
   success: function(data) {
           var dataResults = data.d;
      //get login name  
      var loginName  = dataResults.LoginName.split('|')[1];
      alert(loginName);     
      //get display name
      alert(dataResults.Title);
   }
 });
}
How to Get Login Name and Display Name using SharePoint 2013 REST API
http://www.codeproject.com/Articles/692289/How-to-Get-Login-Name-and-Display-Name-using-Share

No comments:

Post a Comment