
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
10-31-2019 09:47 AM - edited 08-10-2024 08:14 AM
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
Hi there,
Recently a Community thread was posted about the Visual Task Board labels, and adding a new global one. Would this even be possible? I did some research and came with an answer to this. With this article, writing the answer out in more detail.
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!
C |
If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.
Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in? |
Kind regards,
Mark Roethof
ServiceNow Technical Consultant @ Paphos Group
---
- 2,256 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Mark..
So, I am trying to modify tags, and have the sysid of the label, and the code, but it is not working.. still showing the same 7 default labels upon creating a new taskboard.
It probably is in my business rule.. could you show a screenshot of your bus
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
In the business rule, on the 'advanced tab'. should there be anything in the 'condition' label? above the script? Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Mark, Above is 'when to run' tab of my business rule... Next, is the 'actions' tab...
Finally, the 'advanced' tab...
When i create a NEW taskboard, i can only see the same default tags...
however, if i go to the tags, i can see the tag i need to see in all new taskboards...
Any guidance would be very helpful and appreciated....
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Ahhh I finally got it... had to make sure i got the correct table 🙂

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
In which table are the 7 labels that appear by default configured?
or in which table is the business rule that create them when you create a vtb?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
VTB Board Labels; vtb_board_label.list
Label Entry; label_entry.LIST
Hope this helps