Scripted Visual Task Board Card labels [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!
Kind regards,
Mark Roethof
ServiceNow Technical Consultant @ Paphos Group---
Labels:
https://www.servicenow.com/community/developer-articles/scripted-visual-task-board-card-labels-new-york/ta-p/2308556
