Adding “global” Visual Task Board labels [New York]
Visual Task Board Labels
Since New York, you are able to add your own Visual Task Board Labels, on top of the out-of-the-box seven (7) available labels. How this works is described in one of my previous articles (Visual Task Board unlimited labels [New York]).
Adding Labels
Adding Visual Task Board Labels themselves is simply a matter of clicking the plus symbol, typing the label, and choosing a color. That's it.
This new label is uniquely for your current Visual Task Board.
Adding global Labels
What if we would want to have a newly created label, global available? Global, so on every Visual Task Board? With some scripting, this would certainly be possible.
Note that the new label is stored in the "Tags" table and that a relationship record (in the "VTB Board Labels" table) connects the label to the Visual Task Board. Knowing this structure, we could set up scripting to have a Label available on all current and all new Visual Task Boards.
New Visual Task Boards
Now we have a new label, we can set up an After Insert Business Rule which will add the label automatically. Pre-requisites:1) Copy the sys_id of the newly created label [label table];
2) Define a color for your newly created label, color must be a HEX color.
(function executeRule(current, previous /*null when async*/) {
// sys_id of the global label
var labelSysId = '89556cdcdb7c0c10b9f39026db9619cc';
// Color of the global label
var colorStr = '#ffffff';
// Insert the Visual Task Board Label
var grBoardLabel = new GlideRecord('vtb_board_label');
grBoardLabel.initialize();
grBoardLabel.setValue('active', true);
grBoardLabel.setValue('board', current.getUniqueValue());
grBoardLabel.setValue('color', colorStr);
grBoardLabel.setValue('label', labelSysId);
grBoardLabel.setValue('order', 999);
grBoardLabel.insert();
})(current, previous);
Existing Visual Task Boards
So now we did automate having the global label available for new Visual Task Boards. Though existing Visual Task Boards will not have this label available… if wanted, you could achieve this thru below Fix Script. Pre-requisite:
3) Decide if the label should be active by default or not.
// sys_id of the global label
var labelSysId = '46dbe414dbfc0c10b9f39026db961930';
// Color of the global label
var colorStr = '#ffffff';
// Boolean which represents if the label is active, true/false
var activeBool = true;
// Query Visual Task Boards
var grBoard = new GlideRecord('vtb_board');
grBoard.addActiveQuery();
grBoard._query();
while(grBoard._next()) {
// Query if Visual Task Board Label already excists
var gaBoardLabelUnique = new GlideAggregate('vtb_board_label');
gaBoardLabelUnique.addQuery('board', grBoard.getUniqueValue());
gaBoardLabelUnique.addQuery('label', labelSysId);
gaBoardLabelUnique.addAggregate('COUNT');
gaBoardLabelUnique._query();
if(gaBoardLabelUnique._next() && gaBoardLabelUnique.getAggregate('COUNT') == 0) {
// Query for max order of Visual Task Board Labels
var gaBoardLabelCount = new GlideAggregate('vtb_board_label');
gaBoardLabelCount.addQuery('board', grBoard.getUniqueValue());
gaBoardLabelCount.groupBy('board');
gaBoardLabelCount.addAggregate('MAX', 'order');
gaBoardLabelCount._query();
if(gaBoardLabelCount._next()) {
orderInt = parseInt(gaBoardLabelCount.getAggregate('MAX', 'order')) + 1;
// Insert the Visual Task Board Label
var grBoardLabel = new GlideRecord('vtb_board_label');
grBoardLabel.initialize();
grBoardLabel.setValue('active', activeBool);
grBoardLabel.setValue('board', grBoard.getUniqueValue());
grBoardLabel.setValue('color', colorStr);
grBoardLabel.setValue('label', labelSysId);
grBoardLabel.setValue('order', orderInt);
grBoardLabel.insert();
}
}
}
---
And that's it actually. Hope you like it. If any questions or remarks, let me know!
Kind regards,
Mark Roethof
ServiceNow Technical Consultant @ Paphos Group---
Labels:
https://www.servicenow.com/community/developer-articles/adding-global-visual-task-board-labels-new-york/ta-p/2312472
