Background Script
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 01:21 AM
Hi Community,
Using Background script I need to assign the created tag to existing RITMS for which dollar amount is equal to 100k dollar & when the dollar amount is less than to 100k I need to remove the Tag from RITM.How can I achieve this?
Thanks,
Manu
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 01:30 AM
Hi @Manu143
Please find general outline of the background script below-
var thresholdAmount = 100000; // $100,000
var tagName = 'YourTagName'; // Replace 'YourTagName' with the actual tag name
// Query RITMs with dollar amount equal to or less than the threshold
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery('price', '<=', thresholdAmount);
ritmGr.query();
// Iterate over the RITMs and assign or remove the tag
while (ritmGr.next()) {
if (ritmGr.price == thresholdAmount) {
var tagGr = new GlideRecord('sys_tag');
tagGr.addQuery('name', tagName);
tagGr.query();
if (tagGr.next()) {
ritmGr.tags.add(tagGr.sys_id);
ritmGr.update();
gs.info('Tag assigned to RITM: ' + ritmGr.number);
} else {
gs.error('Tag not found: ' + tagName);
}
} else {
// Remove the tag
ritmGr.tags.remove(tagGr.sys_id);
ritmGr.update();
gs.info('Tag removed from RITM: ' + ritmGr.number);
}
}
Please mark my answer helpful and correct.
Regards,
Amit