Business Rule to copy additional comments from sctask to ritm is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 04:10 AM - edited 12-08-2022 04:13 AM
Hi All,
I have two business rules:
1. Copy additional comments from ritm to sctask
2. Copy additional comments from sctask to ritm
First one is working fine and looks as below:
- Before Insert/Update
- Order 100
- Condition: Additonal comments changes
- Script:
(function executeRule(current, previous /*null when async*/ ) {
//To Copy the Additional Comments from RITM to SCTASKs
var compare, ritm_comment2, ritm_comment, task_comment2, task_comment;
ritm_comment = current.comments.getJournalEntry(1);//Remove timestamp and name from additional comment
var regex = new RegExp('\n');
var i = ritm_comment.search(regex);
if (i > 0) {
ritm_comment2 = ritm_comment.substring(i + 1, ritm_comment.length);
}var task_gr = new GlideRecord('sc_task');
task_gr.addQuery('parent', current.sys_id);
task_gr.query();while (task_gr.next()) {
task_comment = task_gr.comments.getJournalEntry(1);//Remove timestamp and name from additional comment
var i1 = task_comment.search(regex);
if (i1 > 0) {
task_comment2 = task_comment.substring(i1 + 1, task_comment.length);
}
compare = ritm_comment2.indexOf(task_comment2);if (compare == -1) // If No match found
{task_gr.comments = "RITM Comments for " + current.number + " : " + ritm_comment2.trim();
task_gr.update();
}
}
})(current, previous);
The second one is not working and it looks as below:
- Before Insert/Update
- Order 100
- Condition: Additonal comments changes
- Script:
(function executeRule(current, previous /*null when async*/ ) {
var grreq = new GlideRecord('sc_req_item');
grreq.addQuery('sys_id', current.getValue('request_item'));
grreq.query();
if (grreq.next()) {grreq.setWorkflow(false);
grreq.comments = current.comments;
grreq.update();}
})(current, previous);
Any suggestions what can be wrong?
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 04:30 AM
Put grreq.setWorkflow(false); after grreq.update(); and try.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 05:40 AM
Now I have:
To copy additional comments from sctask to RITM:
Before Insert/Update, Additional Comments changes, and script:
(function executeRule(current, previous /*null when async*/ ) {
var gr_parent = new GlideRecord('sc_req_item');
if (gr_parent.get(current.parent)) {
gr_parent.comments = current.comments;
gr_parent.update();
gr_parent.setWorkflow(false);
}
})(current, previous);
And is working fine but I have duplicated additional comments as below:
SCTASK:
RITM:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 05:48 AM - edited 12-08-2022 05:48 AM
Yes this is known issue so for this you will have to make below changes in conditions.
1. The BR on RITM: add one condition that requested for is javascript:gs.getUserID(); Reason for this is that, on ritm only requested for user makes any comment.
2. The BR on task table: add one condition that requested for is not javascript:gs.getUserID(); Reason for this is that, on task only support group members add comments and not the end users.
If these conditions are not added, then will always duplicate the comments.
Please mark the answer correct/helpful accordingly.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 04:31 AM
Hi, Can you test your script in background script. If it is working fine there is no issue in the script.
Check the Business rule table name
Check the order of the business rule
Check the same script with 'Before' and ' After'
Suresh.