Skip to content

Commit 2fca83b

Browse files
Adding a new business rule: Add or remove a tag from the ticket whenever the comments are updated. (#1796)
* Create Code.js * Create README.md * Add Business rule: Add or remove tag to the ticket * Rename code.js to code.js * Rename README.md to README.md
1 parent 01bb3d8 commit 2fca83b

File tree

2 files changed

+28
-0
lines changed
  • Server-Side Components/Business Rules/Add or remove a tag from the ticket whenever the comments are updated

2 files changed

+28
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The purpose of this code is to conditionally apply a specific label (label_entry) to an Incident when the person updating the record is the same as the caller. If the update is made by someone else, the label is removed.
2+
This mechanism helps fulfillers quickly identify caller driven updates, enabling faster and more targeted responses. Additionally, it can be leveraged in reporting to track caller engagement.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//Business Rule: After update on the incident table
2+
//Condition: Additional comments changes
3+
//Create on global Tag record ex: Comments added
4+
5+
(function executeRule(current, previous /*null when async*/ ) {
6+
7+
var caller = current.caller_id.user_name;
8+
// Add tag to the incident record if the comments is updated by the caller
9+
if (current.sys_updated_by == caller) {
10+
var add_tag_entry = new GlideRecord('label_entry');
11+
add_tag_entry.initialize();
12+
add_tag_entry.label = '<sys_id of the Tag>';
13+
add_tag_entry.table = 'incident';
14+
add_tag_entry.table_key = current.sys_id;
15+
add_tag_entry.insert();
16+
} else {
17+
// Remove tag from the incident record if the agent responds back to the caller
18+
var remove_tag_entry = new GlideRecord('label_entry');
19+
remove_tag_entry.addEncodedQuery("label=<sys_id of the Tag>^table_key=" + current.sys_id);
20+
remove_tag_entry.query();
21+
if (remove_tag_entry.next()) {
22+
remove_tag_entry.deleteRecord();
23+
}
24+
}
25+
26+
})(current, previous);

0 commit comments

Comments
 (0)