|
1 | | -//Business Rule: After update on the incident table |
2 | | -//Condition: Additional comments changes |
3 | | -//Create on global Tag record ex: Comments added |
| 1 | +// Business Rule: After Update on Incident table |
| 2 | +// Condition: Changes to Additional Comments field |
| 3 | +// Purpose: Add or remove a tag based on whether the update was made by the caller |
4 | 4 |
|
5 | | -(function executeRule(current, previous /*null when async*/ ) { |
| 5 | +(function executeRule(current, previous /*null when async*/) { |
6 | 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(); |
| 7 | + // Replace this with the actual sys_id of the Tag record (e.g., for "Comments added") |
| 8 | + var TAG_SYS_ID = '<sys_id_of_the_Tag>'; |
| 9 | + |
| 10 | + var callerUsername = current.caller_id.user_name; |
| 11 | + var updatedBy = current.sys_updated_by; |
| 12 | + |
| 13 | + if (updatedBy == callerUsername) { |
| 14 | + // Add tag if caller added the comment |
| 15 | + var tagGR = new GlideRecord('label_entry'); |
| 16 | + tagGR.addQuery('label', TAG_SYS_ID); |
| 17 | + tagGR.addQuery('table_key', current.sys_id); |
| 18 | + tagGR.query(); |
| 19 | + |
| 20 | + if (!tagGR.hasNext()) { |
| 21 | + var addTag = new GlideRecord('label_entry'); |
| 22 | + addTag.initialize(); |
| 23 | + addTag.label = TAG_SYS_ID; |
| 24 | + addTag.table = 'incident'; |
| 25 | + addTag.table_key = current.sys_id; |
| 26 | + addTag.insert(); |
| 27 | + } |
16 | 28 | } 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(); |
| 29 | + // Remove tag if someone else (e.g., fulfiller) responded |
| 30 | + var removeTag = new GlideRecord('label_entry'); |
| 31 | + removeTag.addQuery('label', TAG_SYS_ID); |
| 32 | + removeTag.addQuery('table_key', current.sys_id); |
| 33 | + removeTag.query(); |
| 34 | + |
| 35 | + while (removeTag.next()) { |
| 36 | + removeTag.deleteRecord(); |
23 | 37 | } |
24 | 38 | } |
25 | 39 |
|
|
0 commit comments