I have a search result web part based on a display template I made up. I created an action to had items as favorites. This way they appear first in the search result web part and they have a full star icon. Other items have an empty star and appear after favorites items.
and
How I made it:
All my items have a column "FavoriteMembers" which is a people picker with multiple selection. If current user is in the field then he have a full star, if not he have an empty star. I used a managed property to do it.
I manage to update items from display template to enable user to add or remove favorite on clic on the star. (It updates my item well, in real time)
My problem:
If user refresh his browser, item will keeps is old favorite status until the Shareoint search crawled the item again. In SharePoint Online, it takes between 15min and 6 hours (my observation and others).
The solution I'm trying to use:
CAML Query
I want to use a caml query to retrieve the "FavoriteMembers"column content in real time and update the star icon.
I already use CAML Query on other projects and managed to make it works. This time, it's the first time I'm trying to make it in a display template but query keep going in the failed part.
My Code:
function ListItems(){
var clientcontext = new SP.ClientContext.get_current();
var list = clientcontext.get_web().get_lists().getByTitle(currentItemList);
clientcontext.load(list);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Contains><FieldRef Name=\'Title\'/><Value Type=\'Text\'>'+ currentItemTitle +'</Value></Contains></Where></View>');
var collListItem = list.getItems(camlQuery);
clientcontext.load(collListItem);
var currentUser = clientcontext.get_web().get_currentUser();
clientcontext.load(currentUser);
clientcontext.executeQueryAsync(function () {
// some more script
}, function () {
console.log("alert");
});
}
Any advice ? Can someone confirm I can use CAML Query in a display template ?