How to set Search Settings in SharePoint 2013 via CSOM
function updateSearchSettings(searchSenterUrl,resultsPageUrl,Success,Error) {
var context = SP.ClientContext.get_current();
var web = context.get_site().get_rootWeb();
var props = web.get_allProperties();
props.set_item("SRCH_ENH_FTR_URL_SITE",searchSenterUrl);
props.set_item("SRCH_SB_SET_SITE",JSON.stringify({"Inherit":false,"ResultsPageAddress":resultsPageUrl,"ShowNavigation":false}));
web.update();
context.load(props);
context.executeQueryAsync(
function () {
var searchCenterUrl = props.get_item("SRCH_ENH_FTR_URL_SITE");
var searchPageProps = JSON.parse(props.get_item("SRCH_SB_SET_SITE"));
Success(searchCenterUrl,searchPageProps);
},
Error
);
}
//Usage
updateSearchSettings("/sites/search/pages2","/sites/search/pages/default.aspx",function(searchCenterUrl,searchPageProps){
console.log('Search Center Url:' + searchCenterUrl);
console.log('Results Page Url:' + searchPageProps.ResultsPageAddress);
},
function (sender, args) {
console.log("Error: " + args.get_message());
});