Search, SharePoint, Technical

Interactive Ratings in Search Results

I found a great post that saved me a TON of time when working on a solution to bring in interactive ratings of documents to a search results page. Thank you Eugene! (Not sure what your last name is…sorry)

I’m adding to it here because I ran into an issue where the code wasn’t able to pull the client context so was throwing null object errors. This happened after publishing the search results page and was due to sp.js not being loaded. Luckily I’ve run into this before so the fix was quick. I changed his SearchRatingViewModel function code from:


//invoke update whenever rating value changes
vm.rating.subscribe(function () {
loadScript('reputation.js', function() {
vm.updateRating();
});
});

To:

//invoke update whenever rating value changes
vm.rating.subscribe(function () {
loadScript('sp.js', function () {
loadScript('reputation.js', function() {
vm.updateRating();
});
});
});

So the sp.js library gets loaded, which fixed the null object errors.


Leave a Reply

Your email address will not be published. Required fields are marked *