Skip to content

Commit a56fd1f

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

File tree

1 file changed

+38
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)