Configure Search Center URLs in SharePoint 2013 using Javascript CSOM

In SharePoint 2013, I'm trying to access a search object through JavaScript CSOM.

I want to know an object that can give me access to the search settings in the "Site Settings" section. I tried to find the SP object, but I did not find any search there.

My goal is to change the search center URL using JavaScript CSOM.

Thanks in advance!

+4
source share
2 answers

How to set search parameters in SharePoint 2013 through 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()); }); 
+1
source

The search center URL for this website is stored in the Property folder for this website, in RootWeb you can also set the search center URL for the website.

In 2013, the keys have changed since 2010, now they relate to SRCH_ENH_FTR_URL_WEB and SRCH_ENH_FTR_URL_SITE. The code for installing them looks something like this:

 var ctx = new SP.ClientContext.get_current(); var web = ctx.get_site().get_rootWeb(); var props = web.get_allProperties(); props.set_item("SRCH_ENH_FTR_URL_SITE","/sites/search/pages"); web.update(); ctx.load(web); ctx.executeQueryAsync(function () { alert("Search Settings Modified"); }, function() { alert("failed"); }); 
0
source

Source: https://habr.com/ru/post/1469308/


All Articles