0

I currently have an ajax request set up in my javascript to call the search API but this only gives me departments matching whatever I input for query:

$.ajax(
    {
         url: _spPageContextInfo.webAbsoluteUrl + "/_api/search/query?querytext='Department:"
         + query
         + "*'&selectproperties='Department'&sourceid='<removed>'&sortlist='Department:ascending'",
         method: "GET",
         headers: {
             "accept": "application/xml",
         },
             success: onSuccess,
             error: onError
    }
);

How can I query search so that I get ALL departments back? I can do the filtering for distinct departments once I get the data back, but I don't want to search for a particular department. I want all of them.

1

Assuming that you tried Department:* and that did not work, you could try to search by content type. If Department is a site column, you could request all items that have the Content Type that contains that column.

  • No, Department:* returns no results. Department is not a site column, it is part of the search schema and is grabbed from a user profile (which is sync'd from AD). The crawler grabs this when it crawls sps3 on a particular web app. – tnw Feb 14 '14 at 21:33
0

That query won't work because you're querying all items that HAVE a department. If you just want the department, get it from the Managed metadata service. User departments, job titles, and location are synchronized from AD and pumped into the mms app > People > Department.

0

You're searching for a specific Department in your Query. This works for me:

/_api/search/query?querytext='*'&selectproperties='Department'&sourceid='B09A7990-05EA-4AF9-81EF-EDFAB16C4E31'&rowlimit=100

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.