Is it possible to restrict the display of certain information in the boxes? For example, display salaries (stored in a custom attributes) and display them only to managers (who are in a specific access group).
In the same line of thought, could I display information from the logged-in user. For example, to see my salary, grade, etc. and hide this information from the rest of the users who are not the logged-in user.
You can use the following JavaScript code to display fields based on the user's SharePoint Group:
let userInGroup = false;
function CheckUserGroup() {
let groupName = 'MySite Owners'; // required group name
let clientContext = new SP.ClientContext("https://example.sharepoint.com/sites/MySite/"); // URL of your Org Chart
let currentWeb = clientContext.get_web();
let currentUser = clientContext.get_web().get_currentUser();
clientContext.load(currentUser);
let allGroups = currentWeb.get_siteGroups();
clientContext.load(allGroups);
let group = allGroups.getByName(groupName);
clientContext.load(group);
let groupUsers = group.get_users();
clientContext.load(groupUsers);
clientContext.executeQueryAsync(OnSuccess);
function OnSuccess(sender, args) {
let groupUserEnumerator = groupUsers.getEnumerator();
while (groupUserEnumerator.moveNext()) {
let groupUser = groupUserEnumerator.get_current();
if (groupUser.get_id() == currentUser.get_id()) {
userInGroup = true;
break;
}
}
}
}
api.prerenderAction = function(completed){
try {
CheckUserGroup();
}
catch(err) {
connsole.log('Failed to check user group. Error: ', err)
}
finally {
completed();
}
}
api.onBoxRendered((box, itemData) => {
if (userInGroup) {
var $cardFields = $(box.elem).find(".poch-box__fields-container");
$cardFields.append(`<div class="poch-box__field">${itemData.extensionAttribute1}</div>`) // adding new field
}
});
Change ‘MySite Owners’ to an actual SharePoint Group:
let groupName = 'MySite Owners'; // required group name
URL of the site where you have your Org Chart:
let clientContext = new SP.ClientContext("https://example.sharepoint.com/sites/MySite/"); // URL of your Org Chart
and itemData.extensionAttribute1 according to the actual name of the salary field in your data source:
$cardFields.append(`<div class="poch-box__field">${itemData.extensionAttribute1}</div>`) // adding new field