The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Mark Roethof
Tera Patron
Tera Patron

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.

find_real_file.png

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!

đź‘Ť
If this post helped you in any way, I would appreciate it if you hit bookmark or mark it as helpful.

Interested in more articles, blogs, videos, and Share projects on Visual Task Board I published?
Visual Task Board


Kind regards,
Mark

---

LinkedIn

 

Comments
Wintonsl
Tera Contributor

Is there a way to update the label's color on all of my boards if I update from one of my boards?

Karlie
Tera Contributor

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. 

Matt Cordero1
Mega Guru

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...

Niko5
Mega Explorer

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 Roethof
Tera Patron
Tera Patron

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

---

LinkedIn
Community article list

Niko5
Mega Explorer

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 Roethof
Tera Patron
Tera Patron

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

---

LinkedIn
Community article list

Niko5
Mega Explorer

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

Shiva Durga Pra
Tera Contributor

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 

ShivaDurgaPra_0-1702477869526.png

 

Version history
Last update:
‎10-08-2019 08:57 AM
Updated by: