- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-26-2018 09:40 PM
Hi,
I'm copying comments from Approval to RITM and RITM to approval . I've written two business rules , one is on sysapproval_approver table and the other is on sc_req_item. Both are running before Update.
Below are BR's.
Approval to RITM:
var gr = new GlideRecord('sc_req_item');
gr.get(current.sysapproval);
gr.comments = current.comments;
gr.update();
RITM to approval:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('state','requested');
gr.query();
while(gr.next()){
if(gr.getValue('sysapproval')==current.sys_id)
gr.comments = current.comments;
gr.update();
}
})(current, previous);
The issue i'm facing is When i update comments in approval , comments getting updated and RITM business Rule is getting triggered.
Comments in Approval getting twice. How to prevent this.
Eg: please find below image.
Please suggest,
Thanks,
Bhargav reddy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-27-2018 02:00 AM
We had a similar requirement to update request from SC task and update SC task from Request. When we write it to request it was writing back to task making it duplicate.
Our requirement was
1. If user updates on Request, write it to SC task
2. If SC task writes it to request then do not write back to sc task
you can use the below script and modify to fulfill your requirement.
From Request to SC task
addCommentToTask();
function addCommentToTask()
{
var updated_by, requested_for, opened_by;
updated_by=current.sys_updated_by.toString();
requested_for = current.requested_for.user_name.toString();
opened_by = current.opened_by.user_name.toString();
//gs.log(updated_by + ', ' + requested_for + ', ' + opened_by );
//gs.log(current.comments);
var gr1 = new GlideRecord("sc_task");
gr1.addQuery('request', current.sys_id);
gr1.addQuery('state', -5);
gr1.addQuery('u_on_hold_reason', 'pending_caller');
//gr1.addQuery();
gr1.query();
while (gr1.next()) {
//if(current.sys_updated_by,'!=',gr1.sys_updated_by){
if(updated_by == requested_for || updated_by == opened_by){
//gs.log('Ashish 1'+current.sys_updated_by +'Ashish 2 '+gr1.sys_updated_by);
//gs.log(current.comments);
gr1.work_notes = current.comments;
gr1.update();
}
}
}
This script was the major cause and add the below condition solved the problem.
if(updated_by == requested_for || updated_by == opened_by) // this was we are checking if person requesting to update is the requestor or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-27-2018 02:00 AM
We had a similar requirement to update request from SC task and update SC task from Request. When we write it to request it was writing back to task making it duplicate.
Our requirement was
1. If user updates on Request, write it to SC task
2. If SC task writes it to request then do not write back to sc task
you can use the below script and modify to fulfill your requirement.
From Request to SC task
addCommentToTask();
function addCommentToTask()
{
var updated_by, requested_for, opened_by;
updated_by=current.sys_updated_by.toString();
requested_for = current.requested_for.user_name.toString();
opened_by = current.opened_by.user_name.toString();
//gs.log(updated_by + ', ' + requested_for + ', ' + opened_by );
//gs.log(current.comments);
var gr1 = new GlideRecord("sc_task");
gr1.addQuery('request', current.sys_id);
gr1.addQuery('state', -5);
gr1.addQuery('u_on_hold_reason', 'pending_caller');
//gr1.addQuery();
gr1.query();
while (gr1.next()) {
//if(current.sys_updated_by,'!=',gr1.sys_updated_by){
if(updated_by == requested_for || updated_by == opened_by){
//gs.log('Ashish 1'+current.sys_updated_by +'Ashish 2 '+gr1.sys_updated_by);
//gs.log(current.comments);
gr1.work_notes = current.comments;
gr1.update();
}
}
}
This script was the major cause and add the below condition solved the problem.
if(updated_by == requested_for || updated_by == opened_by) // this was we are checking if person requesting to update is the requestor or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-11-2024 09:30 PM
Hi @bhargav1330,
I'm also facing the exact same issue. Could you please share the code you had used for RITM to Approval.
Regards,
Guna Shalini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-20-2019 11:35 PM
Copy comments from RITM to Approval
condition: After, when "Additional Comments Changes", on Insert and Update
//code
(function executeRule(current, previous) {
var compare,ritm_comment2,ritm_comment,approval_comment2,approval_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 app_gr = new GlideRecord('sysapproval_approver');
app_gr.addQuery('sysapproval',current.sys_id);
app_gr.query();
if(app_gr.next())
{
approval_comment =app_gr.comments.getJournalEntry(1);
//Remove timestamp and name from additional comment
var i1 = approval_comment.search(regex);
if(i1 > 0)
{
approval_comment2 = approval_comment.substring(i1+1, approval_comment.length);
}
compare = ritm_comment2.indexOf(approval_comment2);
if(compare == -1) // If No match found
{
app_gr.comments = ritm_comment2.trim();
app_gr.update();
}
}
})(current, previous);
==================================================================
Copy comments from Approval to RITM
condition: After, when "Additional Comments Changes", on Insert and Update
//code
(function executeRule(current, previous ) {
var compare,approval_comment2,approval_comment,ritm_comment2,ritm_comment;
approval_comment =current.comments.getJournalEntry(1);
//Remove timestamp and name from additional comment
var regex= new RegExp('\\n');
var i = approval_comment.search(regex);
if (i>0)
{
approval_comment2 = approval_comment.substring(i+1, approval_comment.length);
}
var ritm_gr = new GlideRecord('sc_req_item');
ritm_gr.addQuery('sys_id', current.sysapproval);
ritm_gr.query();
if(ritm_gr.next())
{
ritm_comment =ritm_gr.comments.getJournalEntry(1);
//Remove timestamp and name from additional comment
var i1 = ritm_comment.search(regex);
if(i1 > 0)
{
ritm_comment2 = ritm_comment.substring(i1+1, ritm_comment.length);
}
compare = approval_comment2.indexOf(ritm_comment2);
if(compare == -1) // If No match found
{
ritm_gr.comments = approval_comment2.trim();
ritm_gr.update();
}
}
})(current, previous);