Hi Sam,
Thank you for your question.
You can do it using our JavaScript framework and JSOM. Let us say you have “LoginId” field in your list which stores login for user. Thus you can use it to find list item in list by current user. Below you can find sample JavaScript which requests list item from list for Org Chart by current user and then drills down to it.
This script will work if you store data in “LoginId” field as plain text like this “domain\userlogin”. If you have different internal name for field where login is stored just find “loginFieldInternalName” variable in the script and specify your own internal name for field like this:
var loginFieldInternalName = "LoginId";
Here is complete script. Just replace “loginFieldInternalName” if required and paste it into JavaScript editor of the configuration wizard.
[code]function getCurrentUserOrgChartId(completed){
var camlQueryTemplate = “{{currentUserLogin}}”;
var listId = renderer.config.ListDataSourceSettings.ListId;
var orgChartIdFieldName = renderer.config.idFieldMapping.InternalFieldName;
var context = SP.ClientContext.get_current();
var web = context.get_web();
var currentUser = web.get_currentUser();
context.load(currentUser);
context.executeQueryAsync(function () {
var currentUserLogin = currentUser.get_loginName();
var originalLogin = currentUserLogin.replace(/.*|/, “”);
console.log(originalLogin);
var list = context.get_web().get_lists().getById(listId);
var camlQuery = new SP.CamlQuery();
var queryText = camlQueryTemplate
.replace("{{loginFieldInternalName}}", loginFieldInternalName)
.replace("{{currentUserLogin}}", originalLogin);
camlQuery.set_viewXml(queryText);
var foundItems = list.getItems(camlQuery);
context.load(foundItems);
context.executeQueryAsync(function () {
console.log(foundItems);
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.");
}
});
})
}
var loginFieldInternalName = “LoginId”;
var isFirstLoad = true;
var currentUserOrgChartId = “”;
getCurrentUserOrgChartId(function(userId){
currentUserOrgChartId = userId;
});
renderer.onLoadingFinished(function(){
if(isFirstLoad){
isFirstLoad = false;
if(currentUserOrgChartId){
renderer.drillDown(currentUserOrgChartId);
}
}
});[/code]
The script has two parts. The first is “getCurrentUserOrgChartId” function which is responsible for querying your SharePoint list by current user. And the second is actual drilling down to the user. I will pay more attention to this. Here is this part of script:
[code]var loginFieldInternalName = “LoginId”;
var isFirstLoad = true;
var currentUserOrgChartId = “”;
getCurrentUserOrgChartId(function(userId){
currentUserOrgChartId = userId;
});
renderer.onLoadingFinished(function(){
if(isFirstLoad){
isFirstLoad = false;
if(currentUserOrgChartId){
renderer.drillDown(currentUserOrgChartId);
}
}
});[/code]
As you see it just requests list item for current user using “getCurrentUserOrgChartId” funciton and then waits for Org Chart loaded event. Inside this event it drills down to the user.