How to Copy Approval comments into RITM, REQ

chanikya
Tera Guru

Hi,

can you help me how to copy Approval comments into RITM, REQ, when RITM was REJECTED. 

 

Not Working

here Approvals comments copying to RITM, but  Not  copied into REQ.

 

approvalcomments();
function approvalcomments()
{
var grr = new GlideRecord('sc_req_item');
grr.get(current.sysapproval);
grr.comments = current.comments;
grr.update();


var gr = new GlideRecord('sc_request');
gr.get(gr.request);
if(gr.next())
{
gr.comments = current.comments+" " +gr.number;
gr.update();
}
}

 

1 ACCEPTED SOLUTION

Working example from my PDI (= tested). Working for Approvals on RITM.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

find_real_file.png

find_real_file.png

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

13 REPLIES 13

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Hard to say exactly for your situation, I don't know how your approval is setup, custom field, etc..

Though an approach could be:

onBefore Business Rule, Update checked, Condition (or thru condition builder) State changes to Rejected.
The scripted:

Example for only the RITM!

(function executeRule(current, previous /*null when async*/) {
	
	var gr = new GlideRecord('sc_req_item');

	if(gr.get('sysapproval')) {
		gr.comments = "Comment copied from approval record:\n\n" + current.comments;
		gr.update();
	}
 
 })(current, previous);

I personally don't like the onBefore + in the script an update on a different record. Though, I think because of the comment type field on your approval, you will need to do onBefore.

Add a gs.info message to the Business Rule, with which you can verify if your Business Rule got triggered. Before moving to production, remove the gs.info message.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

here Approvals comments copying to RITM, but Not copied into REQ.

 

approvalcomments();
function approvalcomments()
{
var grr = new GlideRecord('sc_req_item');
grr.get(current.sysapproval);
grr.comments = current.comments;
grr.update();


var gr = new GlideRecord('sc_request');
gr.get(gr.request);
if(gr.next())
{
gr.comments = current.comments+" " +gr.number;
gr.update();
}
}

Looking at your script, that's correct:

gr.get(gr.request); is nothing yet. So you are not getting a sc_request record.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Working example from my PDI (= tested). Working for Approvals on RITM.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

find_real_file.png

find_real_file.png

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

in case if WE have REQ level Approvals presented on REQ, then is it correct???

 

find_real_file.png 

reqapprovalcomments();
function reqapprovalcomments()
{
var gr = new GlideRecord('sc_request'); // if REQ had approvals 
gr.get(current.sysapproval);
gr.comments = current.comments;
gr.update();
var ghh=new GlideRecord('sc_req_item');
ghh.get('request',gr.sys_id);
ghh.query();
while(ghh.next())
{
//gs.addInfoMessage("RITM numbers is"+ghh.number);//
ghh.comments=current.comments;
ghh.update();
}

}