How to query tags in a form?

Gazal Varshney2
Tera Contributor

Hi,

I have to glide Application table and use those records which are marked as critical in tag field, but I am not able to fetch value tag field value. Please help how I can query this field and glide the records.

thanks,

Gazal Varshney

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

Hi,

tags are stored in this table

Tags [label];

label entries are stored in this table Label Entry [label_entry]

Example: Consider I have marked tag as "Hello" to one incident on incident table; so below script would tell which incident number has that tag

var incArray = [];

var tag = new GlideRecord('label_entry');
tag.addQuery('label.name','Hello');
tag.addQuery('table','incident');
tag.query();

while(tag.next()){
incArray.push(tag.getValue('id_display'));
}

gs.info('Array is: ' + incArray);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

hvrdhn88
Giga Patron

the screenshot which you have shared, it has not any tag value. 

 

tag record stored in table "label_entry" and there is column label , which store the tag value. 

 

 

Ankur Bawiskar
Tera Patron

Hi,

tags are stored in this table

Tags [label];

label entries are stored in this table Label Entry [label_entry]

Example: Consider I have marked tag as "Hello" to one incident on incident table; so below script would tell which incident number has that tag

var incArray = [];

var tag = new GlideRecord('label_entry');
tag.addQuery('label.name','Hello');
tag.addQuery('table','incident');
tag.query();

while(tag.next()){
incArray.push(tag.getValue('id_display'));
}

gs.info('Array is: ' + incArray);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

hvrdhn88
Giga Patron

sample code to fetch the tag value. 

 


var gr= new GlideRecord('label_entry');
gr.addQuery('id_display','INC0010367');// here you will add ticket number 
gr.addQuery('table','incident');
gr.query();

while(gr.next()){
gs.print ('Tag is: ' + gr.label.getDisplayValue());

}