1

I'm trying to build a query to retrieve list items using the REST API. Is there a way to expand on certain fields, but still bring back every other field? This is for use within a SharePoint-hosted add-in.

Whole Query:

appWebUrl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle(@name)/items?" + "@target='" + webUrl + "'&@name='" + listName + "'" + "&$select=ID,Title,Request_x0020_Status,mpsRequestStatus,Request_x0020_Estimated_x0020_Ho,RoutingPriority,Priority,Request_x0020_Description,Request_x0020_Response_x0020_Des,Assigned_x0020_To/Title&$expand=Assigned_x0020_To/Id"

The problem is that there are some lists that have some of the fields specified in the query while others do not. Originally, I didn't have any selects or expands, so that the data retrieved was whatever that's available, which worked great. I needed to expand the AssignedTo field in order to get the user's name and if I left out the other fields, then the call would just bring back that field's data only. Is there a way to expand on AssignedTo (or another field), but not limit it to that only? Thanks in advance.

2 Answers 2

0

If you add select clause then that will limit the fields that is being brought back.

If you are worried about the URL length then you can also try CAML query along with JSOM or REST.

1
  • I know, but don't I have to use select in order to use expand? And I can't use CAML since I'm doing cross domain calls and there were issues authenticating the different client contexts. I first tried CAML since it's easier to gather up what I need.
    – LaLaLottie
    Commented Jul 26, 2016 at 20:22
0

I found a way. So I have to use select if I use expand so I just changed this part:

$select=*,Assigned_x0020_To/Title&$expand=Assigned_x0020_To/Id

It still collects all the fields, but makes sure to expand the specified field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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