I am using JSlink file and using two functions (OnPreRender, Item).
I want to customize Item rendering but before that I want to get data from another list using OnPreRender. The issue I am facing that Item function executes before OnPreRender. Please help how can stop execution of Item until OnPreRender finishes. The below is the code.
(function () {
function OnPreRenderDocItemTemplate(renderCtx) {
SP.SOD.executeOrDelayUntilScriptLoaded(loadContext, 'sp.js');
function loadContext() {
var context = SP.ClientContext.get_current();
var web = context.get_web();
currentUser = web.get_currentUser();
context.load(currentUser);
context.executeQueryAsync(onSuccessMethod, onRequestFail);
}
}
function onSuccessMethod(sender, args) {
var account = currentUser.get_loginName();
var currentUserAccount = account.substring(account.indexOf("|") + 1);
alert(currentUserAccount);
//Also needs to write logic to get data from another list
}
// This function runs if the executeQueryAsync call fails.
function onRequestFail(sender, args) {
alert('request failed' + args.get_message() + '\n' + args.get_stackTrace());
}
function OnPreRenderItem(renderCtx) {
// My Login not yet
alert("test");
return RenderItemTemplate(renderCtx);
}
function RegisterDocViewTemplate() {
var viewContext = {};
viewContext.Templates = {};
viewContext.Templates.OnPreRender = OnPreRenderDocItemTemplate;
viewContext.Templates.Item = OnPreRenderItem;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(viewContext);
}
ExecuteOrDelayUntilScriptLoaded(RegisterDocViewTemplate, 'clienttemplates.js');
})();