How do I lookup tags associated with any task record via script query?

samfindlay94
Tera Contributor

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;Tags.png

Sohail Khilji
Kilo Patron

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

LinkedIn - Lets Connect

Voona Rohila
Tera Patron

Hi @samfindlay94 

Check label_entry Table which has Tag Name and It's related record.

VoonaRohila_0-1713858089425.png

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

View solution in original post

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'));
}

Not applicable

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