function getCurrentUserOrgChartId(completed, error) {
var camlQueryTemplate = "<View><Query><Where><Eq><FieldRef Name='{{loginFieldInternalName}}'/><Value Type='Text'>{{currentUserLogin}}</Value></Eq></Where></Query></View>";
var listId = renderer.config.ListDataSourceSettings.ListId;
var orgChartIdFieldName = renderer.config.idFieldMapping.InternalFieldName;
var context = SP.ClientContext.get_current();
renderer.dataProvider.getCurrentUserAccountName(function (currentUserLogin) {
console.log("currentUserLogin:", currentUserLogin);
currentUserLogin = currentUserLogin.replace(/.*\|/, "");
var list = context.get_web().get_lists().getById(listId);
var camlQuery = new SP.CamlQuery();
var queryText = camlQueryTemplate
.replace("{{loginFieldInternalName}}", loginFieldInternalName)
.replace("{{currentUserLogin}}", currentUserLogin);
console.log("queryText: ", queryText);
camlQuery.set_viewXml(queryText);
var foundItems = list.getItems(camlQuery);
context.load(foundItems);
context.executeQueryAsync(function () {
f = foundItems;
var en = foundItems.getEnumerator();
if (en.moveNext()) {
var fieldValuesForCurrentUser = en.get_current().get_fieldValues();
var currentUserOrgChartId = fieldValuesForCurrentUser[orgChartIdFieldName];
completed(currentUserOrgChartId);
} else {
console.log("List item for current user not found.");
}
}, function (sender, args) {
error(args);
});
});
}
var currentUserId = "";
var loginFieldInternalName = "AccountName";
renderer.prerenderAction = function (completed) {
getCurrentUserOrgChartId(function (userId) {
currentUserId = userId;
completed();
}, function (errorArgs) {
console.log(errorArgs);
completed();
});
}
renderer.onInitialLoadingFinished(
function () {
if (currentUserId) {
renderer.drillDown(currentUserId);
}
}
);