Skip to content

Commit deb75b1

Browse files
authored
Create update_notes_tag_removal.js
Business rule to add work notes on record if notes for tag removal are allowed. It is very hard to track who removed the tag to the record and when, this will help to manage to understand who has removed what tags on record.
1 parent a56fd1f commit deb75b1

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**********************BR COnfig Start***************************/
2+
/*
3+
When: before
4+
order: 100
5+
delete: true
6+
Filter: labelISNOTEMPTY^label.nameISNOTEMPTY^EQ
7+
*/
8+
/**********************BR COnfig End***************************/
9+
(function executeRule(current, previous /*null when async*/ ) {
10+
// Check if logging for tag removals is enabled
11+
if (gs.getProperty('custom.tag_entries.log_removal').toString() == "true") {
12+
var current_table = current.getValue('table'); // Retrieve the name of the current table
13+
var allowed_tables = gs.getProperty('custom.tag_entries.tables'); // Get the list of allowed tables from properties
14+
allowed_tables = allowed_tables.split(','); // Split the string into an array
15+
16+
// Verify if the current table is in the allowed list
17+
if (allowed_tables.indexOf(current_table) > -1) {
18+
var gr_task = new GlideRecord(current_table); // Create a GlideRecord object for the current table
19+
try {
20+
// Query the record using sys_id stored in table_key
21+
gr_task.addQuery("sys_id", current.table_key.getValue());
22+
gr_task.query(); // Execute the query
23+
24+
// If the record is found, update work_notes if the field is valid
25+
if (gr_task.next()) {
26+
if (gr_task.isValidField('work_notes')) {
27+
gr_task.work_notes = "Tag removed: " + current.getDisplayValue('label'); // Append removal info to work notes
28+
gr_task.update(); // Save the changes made to work notes
29+
}
30+
}
31+
} catch (e) {
32+
// Log any exceptions encountered during execution
33+
gs.log("Exception occurred in the business rule Updating record when tagged" + e.message);
34+
}
35+
}
36+
}
37+
})(current, previous);

0 commit comments

Comments
 (0)