I have been asked to add relevant images into each user box if the user has a role of Fire Marshal, First Aider or Mental Health First Aider. Some users have two or all three of these roles.
I've followed the guidance here, but it is only working when I apply the code for one role within the Plumsail org chart. As soon as I add the extra code for the other roles, the images don't show up.
For example, when I add the code for Fire Marshal all is well and you can see the image -
As soon as I add the extra code for First Aider for instance, no images show.
This is my JavaScript code:
//Fire Marshal
api.onBoxRendered((box, itemData) => {
if (itemData.RelevantRoles == "Fire Marshal") {
console.log($(box.elem))
var $card = $(box.elem).find(".poch-box__content");
var roleSpan = $("
");
$card.append(roleSpan);
}
});
//First Aider
api.onBoxRendered((box, itemData) => {
if (itemData.RelevantRoles == "First Aider") {
console.log($(box.elem))
var $card = $(box.elem).find(".poch-box__content");
var roleSpan = $("
Your code has two api.onBoxRendered events. Events can be initialized only once, so code for other roles should be placed in one event like so:
//Fire Marshal & First Aider
api.onBoxRendered((box, itemData) => {
var relevantRoles = itemData.RelevantRoles;
if (relevantRoles == "Fire Marshal" || relevantRoles == "First Aider") {
var $card = $(box.elem).find(".poch-box__content");
var roleSpan = $("HTML CODE");
$card.append(roleSpan);
}
});
In this case, the "if" block will go through if relevantRoles of this user are either 'Fire Marshal' or 'First Aider'. If you want separate images for each, use the following code:
//Fire Marshal & First Aider
api.onBoxRendered((box, itemData) => {
var relevantRoles = itemData.RelevantRoles;
if (relevantRoles) {
var $card = $(box.elem).find(".poch-box__content");
var roleSpan;
if (relevantRoles == 'Fire Marshal') {
roleSpan = $("FIRE MARSHAL IMAGE");
} else if (relevantRoles == 'First Aider') {
roleSpan = $("FIRST AIDER IMAGE");
}
$card.append(roleSpan);
}
});
Thank you for that information - I have tried it and it's working for the separate roles. What if a user has both roles - how do I show both of the images for both roles?
Happy Monday! I managed to figure out how to show more than one image/icon if a user has more than one relevant role. Now, how do I place the images/icons next to each other in a line from left to right instead of underneath each other please?
JS Code =
api.onBoxRendered((box, itemData) => {
var relevantRoles = itemData.RelevantRoles;
if (itemData.RelevantRoles.includes("Fire Marshal")) {
console.log($(box.elem))
var $card = $(box.elem).find(".poch-box__content");
var roleSpan = $("
");
$card.append(roleSpan);
}
if (itemData.RelevantRoles.includes("First Aider")) {
console.log($(box.elem))
var $card = $(box.elem).find(".poch-box__content");
var roleSpan = $("");
$card.append(roleSpan);
}
if (itemData.RelevantRoles.includes("Mental Health FAider")) {
console.log($(box.elem))
var $card = $(box.elem).find(".poch-box__content");
var roleSpan = $("");
$card.append(roleSpan);
}
});