- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 12:28 AM
I would like to look up tags associated with a specific Incident record using a script.
How can I achieve this? As far as I can tell there is no "Tag" column on Incident/Task table.
When running a lookup and printing a result I only receive a blank value;
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 12:39 AM - edited 04-23-2024 01:15 AM
try :
var id = '35d93fd2333ddfc00db9b14ffe9619b0'; // INC SYS ID
var inc = new GlideRecord("incident");
inc.get(id);
var le = new GlideRecord("label_entry");
le.addEncodedQuery('urlLIKE' + id);
le.query();
if (le.next()) {
var ll = new GlideRecord("label");
ll.get(le.label);
gs.print(ll.name); // prints tag value
}
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 12:41 AM
Check label_entry Table which has Tag Name and It's related record.
You can query this table and get the Tag Names.
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
5x ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 12:51 AM
Lovely thanks Rohila V. I was able to lookup the 'table_key' value in this table and get the results I needed
var gr = new GlideRecord('label_entry');
gr.addQuery('table_key', '40e24e5c1bf98e10d5d9748bd34bcb2d');
gr.query();
if (gr.next()) {
gs.print(gr.title);
gs.print(gr.getDisplayValue('label'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 01:03 AM
Hi @samfindlay94 ,
I tried your problem in my PDI and it works for me please check below script
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', 'fe5457139329c2100d5170918bba10b9');
gr.query();
if(gr.next()){
gs.print(gr.number);
var labelGR = new GlideRecord('label_entry');
labelGR.addQuery('table_key', gr.sys_id);
labelGR.addEncodedQuery('titleLIKE' + gr.number);
labelGR.query();
if(labelGR.next()){
gs.print("here = " + labelGR.getDisplayValue('label'));
}
}All the tags entry get stored in label_entry table so we need to do GlideRecord on the label_entry table
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak