7 thoughts on “OData $expand not working – SharePoint REST API

  1. I think you may be misrepresenting the power of this FieldValuesAsText command or conflating it with what $expand uaually does. FieldValuesAsText gives you one and only one property of a complex item and you seemingly do not get to determine which property it is. For instance, for a URL field, I may want the Description property (especially if I am looking for the status of a workflow). I do not want the actual URL. I see no way to pull the Description property of a SP.FieldUrlValue. Do you? If you can demonstrate that then clearly the misunderstanding is on my side.

    Just to be clear, your article is indicating that $expand=Field/Property functionality is now replaced by FieldValuesAsText and I disagree.

    Like

    • Actually no. I have also mentioned in the article that, unless there’s an obligation to use the getitems API, the recommended approach would be to use the items API defined here, https://piyushksingh.com/2017/08/31/retrieve-lookup-managed-metadata-and-person-or-group-data-sharepoint/. Even in my example, defined in the link, I have demonstrated to expand two distinct properties of the same Author field. So, we do have a choice to expand any given property. And this is how a REST call should work.

      However, the issue here is that, the standard $expand does not work on the getitems API (defined above in the post), which is strange considering, it’s still very much a REST call! But unlike the items API, getItems allows you to post CAML request. So, it has it’s advantages as well. Hence, in such a scenario, we can leverage FieldValuesAsText, which covers most of the test cases, if not all.

      Like

  2. Hi Piyush, just a heads up when using exapand on FieldValuesAsText or FieldValuesAsHTML – it doesn’t work on lookup fields. It will get you the ID of the item instead of the text/html value of the lookup.

    Microsoft confirmed this is a bug, seems like they are not interested in fixing it though so there is no other way to get it then making a separate request for each item…

    Liked by 1 person

  3. Hi Piyush, your approach basiclly helps when we have to avoid double looping, like get the items and also process each item using getitem and expand, Your solution helped me a lot. case by case this should be used not as a replacement of expand of getitem. Cheers

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.