2

I want to apply Search functionality only on Custom List in SharePoint using Rest API or CAML query.

  • I already tried that rest api example:

    $.getJSON("https://SharePointURL/_api/search/query?
    querytext='QueryText*+Path:https://SharePointListPath", function(data){
        console.log(data);
    });
    

but it take too much of JSON data. Therefore any example to make it simple.

Visit this URL: Calling SharePoint Search Using Rest

Go through this code:

function getSearchResultsUsingREST(queryText) {
    // search can use the app web URL as the base, so no need to use SP.AppContextSite(@target) to access the host web..
    var searchUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/search/query?querytext='" + queryText + "'";
    var executor = new SP.RequestExecutor(_spPageContextInfo.webAbsoluteUrl);
    executor.executeAsync(
        {
            url: searchUrl,
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            success: onGetSearchResultsSuccess,
            error: onGetSearchResultsFail
        }
    );
}

function onGetSearchResultsSuccess(data) {
    var jsonObject = JSON.parse(data.body);
    var results = jsonObject.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;
    if (results.length == 0) {
        $('#related-content-results').text('No related documents were found');
    }
    else {
        var searchResultsHtml = '';
        $.each(results, function (index, result) {
            searchResultsHtml += "<a target='_blank' href='" + result.Cells.results[6].Value + "'>" + result.Cells.results[3].Value + "</a> (" + result.Cells.results[10].Value + ")<br />";
        });
        $('#related-content-results').html(searchResultsHtml);
    }
}

function onGetSearchResultsFail(data, errorCode, errorMessage) {
    $('#related-content-results').text('An error occurred whilst searching for related content - ' + errorMessage);
}

but var results take 48 cells which doesn't contain Custom List field.

Thanks for help!

1 Answer 1

1

You have to call the REST endpoint for additional Fields explicitly with:

&selectproperties=[internalName],[internaleName]

SharePoint endpoint and Search documentation

Search has different syntax

iSearch

4
  • Please! put some code rather than link. Jun 8, 2017 at 8:58
  • Okay, that selectproperties IS code. It is clear you know nothing about REST endpoints and are probably copy/pasting code you do not understand. RTFM! Jun 8, 2017 at 9:00
  • What [internalName] suppose to. Is it custom field name inside custom list. Jun 8, 2017 at 9:04
  • Read the F* Manual Jun 8, 2017 at 9:05

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.