2

I've been trying to use SharePoint REST API to retrieve a number of files on my site but for some reason, if it does tell me the name or descriptions of the files, it returns null for every single custom columns I have for those files.

Here's the code I use:

const path = "Path:" + AppState.context.pageContext.web.absoluteUrl + "/* ";
const url = AppState.context.pageContext.web.absoluteUrl + "/_api/search/query?querytext='" + path + "IsDocument:true'&selectproperties='Status,Title,Path,Created,Description,MGS_Hierarchy'";

and here are the example of a result:

Results of the query

As you can see, the "Status" and "MGS_Hierarchy" values are null, even tough they are set in the list:

enter image description here

The two columns are inherited from a custom content type. I don't know if it changes something.

Any help is greatly appreciated.

1
  • Just confirming. Are those custom site columns added to document library? Are you using correct managed property names for columns? Apr 6, 2022 at 9:48

2 Answers 2

0

You have to use the managed property names for the custom columns to retrieve custom column values using SharePoint Search REST API.

Make sure you are using correct managed property names for the custom columns.

You can find the managed property names from Search Schema in site settings.

Follow below links for more information:

  1. How to Identify Custom Property Names in SharePoint
  2. SharePoint Search REST API overview
1
  • This doesn't tell a person how to solve the issue. Sep 14, 2023 at 21:23
0

during my test i had the same issue and i found out that the way to retrieve these fields is by putting them in the query, try changing your query to this

(IsDocument:true) AND (MGS_Hierarchy:*)

Doing this will bring them.

Be warned that on another site we had a similar issue but the search was being compromise because we had different list that some did not have the field added, and this query was for some reason only bringing the items who had this column so we changed the query to

(IsDocument:true) OR (MGS_Hierarchy:*)

And this time it got all the documents but the ones who did not have the field added the value was null.

If someone has a better way please let me know i am also interested in this.

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.