script to get approval rejection comment from sysapproval_approver table , in flow editor.

surajjha
Tera Contributor

Dear community leaders,

I have a custom record producer where i am using Flow designer for approval and rejection.

In case of rejection , comment is mandatory and same has to be reflect in my record producer.

I am using below script in my flow designer but not working, please help:


var apv = new GlideRecord('sysapproval_approver');
apv.addQuery('sysapproval',current.sys_id);
apv.addQuery('comments','!=',''); // add this to only find approvals that have comments on them
apv.query();
while (apv.next()) { // change if to while so it will go through all approvals with comments
//gs.info(apv.comments.getJournalEntry(-1)); // add approver name here
apv = fd_data.trigger.current.comments.getJournalEntry(-1);
//sn_customerservice_technician_claims.u_approvers_comment = fd_data.trigger.current.comments.getJournalEntry(-1);
apv .update();
return apv;
}*/
 
screen shots are below:
 
Flow designer:

find_real_file.png

 

Approval :

find_real_file.png

 

 

Record producer:

find_real_file.png

9 REPLIES 9

Mark Roethof
Tera Patron
Tera Patron

Hi there,

"I am using below script in my flow designer but not working". Can you describe what's not working?

Also is your script a literal copy/paste? Asking because if I see something like this, this will never work:

apv .update();

Notice the space.

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

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

My script is not working , even approval won't triggered.

if i removed this script my flow is working and approval got triggered.

 

My requirement is to get the Rejection comment entered by approver into my record producer "Additional approval field".

 

Ankur Bawiskar
Tera Patron
Tera Patron

@surajjha 

can you share your flow is running on the record on which you want to update?

if yes then do this

var comments = [];
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
var apv = new GlideRecord('sysapproval_approver');
apv.addQuery('sysapproval',fd_data.trigger.current.sys_id).addOrCondition('document_id', fd_data.trigger.current.sys_id);
apv.addQuery('state', 'rejected');
apv.query();
while (apv.next()) {
	// remove the timestamp and user information and just get the comments value
	var comments = apv.comments.getJournalEntry(1).replace(dateRE, '');
	comments.push(comments.toString());
}
return comments.toString();

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

 
Below code is working :
 
 

var comment = "";

var approvalrec = new GlideRecord('sysapproval_approver');
approvalrec.addEncodedQuery('state=rejected^document_id='+fd_data.trigger.current.sys_id);
approvalrec.query();
if(approvalrec.next()){
var comments = new GlideRecord('sys_journal_field');
comments.addEncodedQuery('nameSTARTSWITHsysapproval_approver^element=comments^element_id='+approvalrec.getUniqueValue());
comments.orderByDesc('sys_created_on');

comments.query();
if(comments.next()){
comment+=(comments.getDisplayValue('value'));
}
}

return comment;