Using Different tags in ServiceNow catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago - last edited a month ago
Hello Everyone,
I need to update a catalog in ServiceNow where a specific tag must be applied automatically after an incident is created.
In my Record Producer, I have a country variable with five country options. I have also created five different tags in System Definition → Tags, each with its own sys_id.
Right now, my script applies only one tag (shown below), and it gets added to every incident regardless of the selected country. What I need is country‑based tagging.
For example:
- If the user selects Belgium, then the NW_CE_BE tag should be applied,
- If they select Romania, then NW_CE_RO should be applied,
- and the same logic should work for all five countries.
Below is the current example where only one hard‑coded tag is being applied:
I need help modifying this so that the correct tag is added based on the country selected in the Record Producer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
hey @ArunG29061990
Avoid hardcoding sys_ids because they differ between DEV / TEST / PROD. Instead, query the tag by its name.
Script
// Get selected country from Record Producer variable
var selectedCountry = producer.country;
var tagName = "";
// Map country to tag name
switch (selectedCountry) {
case "Belgium":
tagName = "NW_CE_BE";
break;
case "Romania":
tagName = "NW_CE_RO";
break;
case "Germany":
tagName = "NW_CE_DE";
break;
case "France":
tagName = "NW_CE_FR";
break;
case "Netherlands":
tagName = "NW_CE_NL";
break;
}
// Apply tag if found
if (tagName) {
var labelGR = new GlideRecord('sys_label');
labelGR.addQuery('name', tagName);
labelGR.query();
if (labelGR.next()) {
var labelEntry = new GlideRecord('label_entry');
labelEntry.initialize();
labelEntry.label = labelGR.sys_id;
labelEntry.table = 'incident';
labelEntry.table_key = current.sys_id;
labelEntry.insert();
}
}
*************************************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
thanks @vaishali231
I have tried this but not working for me. this code is not adding any tag in incident. I can manage the sys_ids in all environments so if possible and easy can we use sysids?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
// Determine selected country
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
hey @ArunG29061990
add log in above script and check what errors come also share a screenshot
