
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
10-08-2019 08:57 AM - edited 08-10-2024 08:19 AM
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
Hi there,
With New York, the labels functionality on Visual Task Boards has changed drastically. Instead of the maximum of 7 labels on a Visual Task Board, one can add unlimited labels to a Visual Task Board! I've described how this technically works and which tables are involved in a previous article (Visual Task Board unlimited labels [New York]). This article goes a step further: What if you would like to script adding labels to Visual Task Board Cards?
Recently Jon Ulrich did a nice job on "An automatic task board labeling system". Vladimir also described "Adding Visual Task Boards Labels through a script". Both are unfortunately based on pre-New York.
Data structure
On a Visual Task Board, Cards are being displayed. The Card representing a Task. On the Card, one or more Labels can be tagged. So how does this work? Below an example with a Private Task [vtb_task].
Key is the Visual Task Board Card [vtb_card]. This record contains references to:
- Task [task];
- Visual Task Board [vtb_board];
- Visual Task Board Lane [vtb_lane].
The labels are now stored in the Tag table [label]. This table is referenced through the Visual Task Board Label table [vtb_board_label] and the Label Entry table [label_entry].
The Visual Task Boad Labels record contains references to:
- Visual Task Board [vtb_board];
- Tag [label].
The Label Entry record contains references to:
- Tag [label];
- Table and Table key.
Scripting labels on Cards
Time to translate the above structure into scripting. For example, we could set up a Business Rule which runs on insert of a Visual Task Board Card on a certain Visual Task Board. This could well be achieved through the conditions.
For testing, let's say the label we automatically want to add is the "High Priority" label.
var labelStr = 'High Priority';
var grLabel = new GlideRecord('label');
grLabel.addQuery('name', labelStr);
grLabel.addQuery('viewable_by', 'everyone');
grLabel._query();
if(grLabel._next()) {
var grLabelEntry = new GlideRecord('label_entry');
grLabelEntry.initialize();
grLabelEntry.setValue('label', grLabel.getUniqueValue());
grLabelEntry.setValue('table', current.task.sys_class_name);
grLabelEntry.setValue('table_key', current.task);
grLabelEntry.insert();
}
Hmmm, labelStr looks like a string, is that oke? Actually, it is. The Tag records [label] which are "Viewable by" "Everyone", have a unique name.
The script itself isn't that huge and difficult. Obviously, if you also want to script adding a Task on a Visual Task Board with Labels, you would need to go through the whole structure like described in the previous paragraph.
---
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
---
- 4,343 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Is there a way to update the label's color on all of my boards if I update from one of my boards?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
How would I go about writing a business rule on the VTB card table when the card changes lanes then remove a certain label? Thank you in advance.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Using a Business Rule, how can you check for the existence of a tag/label on a Task (Story/Defect) on a VTB? We are using SN New York...
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Is there a way to add the label based on a field on the story?
I tried to follow the same logic that you have in the script but the label doesn't apply based on a field in the story.
I would like a label to be applied when a story has been inserted/updated in the visual task board when blocked is true

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Yes that should be possible. You can just write a Business Rule or Flow which adds the label, when a story is inserted/updated with blocked is true.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mark,
Would you be able to give some hints on how that business rule would be created?
I tried creating the business rule for vtb_card table but when I dot walk it to the blocked field of the story, it doesn't create the record in the label_entry table
thanks

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Can you share which Topic you opened for this? Then I can have a look. Please also supply what you exactly already tried.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I didn't post the question to the forum as I came across your article first.
I am using ServiceNow with the Paris version and here's what I have tried:
- create a new business rule for Visual Task Board Card [vtb_card] table
- When to run: after insert/update
filter condition: Board is TestBoardName and Task.Agile story.Blocked is true
- script:
(function executeRule(current, previous /*null when async*/) {
var labelStr = 'Blocked';
var grLabel = new GlideRecord('label');
grLabel.addQuery('name', labelStr);
grLabel.addQuery('viewable_by', 'everyone');
grLabel.query();
if(grLabel._next()) {
var grLabelEntry = new GlideRecord('label_entry');
grLabelEntry.initialize();
grLabelEntry.setValue('title', 'Test ' + 'Blocked');
grLabelEntry.setValue('label', grLabel.getUniqueValue());
grLabelEntry.setValue('table', current.sys_class_name);
grLabelEntry.setValue('table_key', current.task);
var target = "https://devinstance.service-now.com/vtb_card.do?sys_id=" + current.task + "&sysparm_view=";
grLabelEntry.setValue('target', target);
grLabelEntry.insert();
}
})(current, previous);
I also checked the business rule debug and it looks like the business rule isn't triggered when the story's blocked field is set to true.
I then also tried to create the business rule for rm_story table instead but then not able to find the relationship between the story to link it to the vtb_card and vtb_board etc.
Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
After creating a label in VTB, the label shows in tag,
Is there any way to stop showing in the assign tag?
example: created 2 labels with names 5, 6
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Sorry for digging into an old topic, but has anyone been able to implement this so that when a story is marked as Blocked, it automatically adds the "Blocked" label to the tile on VTB? I've tried different ways, but it doesn't work. It does create an entry in "label_entry" with all the necessary data, but it doesn't show the label on to the mentioned story on VTB. Could I have miss something? Any additional dependencies? I tried with BRules on rm_story and also on mentioned there "vtb_card".
EDIT: Hello Guys, it seems that I prepared solution, this is async BR on rm_story, in my scenario it reflect priority field to appropriate labeling on VTB. It is not refactored code so everybody can adjust all stuff, but the root mechanism is there. It should works, as it works for me. It contains also a part which removing old labeling (coz in my scenario only one label was required for story priority, so each time it removes old one and set current priority label). Condition for BR is as you expected changing of priority 🙂 I hope that it helps someone 🙂
(function executeRule(current, previous /*null when async*/ ) {
var priority = current.getDisplayValue('priority');
var labelStr = '';
if (priority == '1 - Critical') {
labelStr = 'High Priority';
} else if (priority == '2 - High') {
labelStr = 'Defect';
} else {
labelStr = 'Low Priority';
}
var gr = new GlideRecord('vtb_card');
gr.addQuery('task.sys_id', current.getValue('sys_id'));
gr.query();
if (gr.next()) {
var grLabel = new GlideRecord('label');
grLabel.addQuery('name', labelStr);
grLabel.addQuery('viewable_by', 'everyone');
grLabel.query();
if (grLabel.next()) {
var grLabelEntry = new GlideRecord('label_entry');
grLabelEntry.addQuery('table_key', gr.getUniqueValue());
grLabelEntry.query();
while (grLabelEntry.next()) {
grLabelEntry.deleteMultiple();
}
grLabelEntry.initialize();
grLabelEntry.setValue('label', grLabel.getUniqueValue());
grLabelEntry.setValue('table', 'vtb_card');
grLabelEntry.setValue('table_key', gr.getUniqueValue());
grLabelEntry.setValue('id_type', 'Visual Task Board Card')
grLabelEntry.setValue('title', gr.getDisplayValue('board'));
grLabelEntry.setValue('url', 'vtb_card.do?sys_id=' + gr.getUniqueValue() + '&sysparm_view=');
grLabelEntry.insert();
}
}
})(current, previous);