1

I need a REST query to get field values in a SharePoint list. Internal name of the List is People and it has Id, Title, ShortName and Age columns. So REST Query is

_api/web/lists/GetByTitle('People')/items?select = Id,Title,ShortName,Age

There is a requirement to get ShortName as Name. Is there any equivalent Alias to query like

ShortName as Name

So full query is looks like,

_api/web/lists/GetByTitle('People')/items?select = Id,Title,ShortName as Name,Age

Applying name after retrieval is not an option. I need a "REST" solution and need to know whether this is capable or not with just a REST Query.

1

To get the Domain\username in your Spreadsheet column, you need to create single line text column column called UserName and assign the =Me value in Calculated Value text box. This column will give you the alias name of the user who is entering the item in list.

Then, Create calculated column named as DomainUser. In this column, you need to concatenate your Domain with Loggedin User name instead of work email id. Ex: US\username.

Code

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);
}
});
}

Refer: https://www.codeproject.com/Articles/692289/How-to-Get-Login-Name-and-Display-Name-using-Sha

  • Is there any "REST" solution to the problem? – Gurusinghe Oct 16 '17 at 11:35
0

As per Microsoft there is not rest endpoint for using alias $select

For your reference you look at the endpoints offered

Microsoft reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.