Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

All Approval record comments are not added in Parent record.

Nikhil80
Tera Contributor

Hello Community,

 

I have a problem where I am trying to add comments of approval records to Parent record, this parent record have more then one approvals.
The script which i have written is adding comments from only 1 approval record.
This script I have on Flow designer script for work notes field.

Script:

var RecordID = fd_data.trigger.current.sys_id;
var appRec = new GlideRecord('sysapproval_approver');
appRec.addQuery('document_id',RecordID);
appRec.query();
while (appRec.next()) {
    var comments;
  comments = appRec.comments.getJournalEntry(1);
var name = appRec.approver.name.getDisplayValue();
return "Case is Approved by " + name + '\n' + comments;
}

NikilB_0-1706705032448.png

 

1 ACCEPTED SOLUTION

Aniket Chavan
Tera Sage
Tera Sage

Hello @Nikhil80 ,

 

Please give a try to the code below and see how it works for you.

var RecordID = fd_data.trigger.current.sys_id;
var appRec = new GlideRecord('sysapproval_approver');
appRec.addQuery('document_id', RecordID);
appRec.query();

var allComments = "";

while (appRec.next()) {
    var comments = appRec.comments.getJournalEntry(1);
    var name = appRec.approver.name.getDisplayValue();
    allComments += "Case is Approved by " + name + '\n' + comments + '\n';
}

return allComments;

 

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket

 

View solution in original post

1 REPLY 1

Aniket Chavan
Tera Sage
Tera Sage

Hello @Nikhil80 ,

 

Please give a try to the code below and see how it works for you.

var RecordID = fd_data.trigger.current.sys_id;
var appRec = new GlideRecord('sysapproval_approver');
appRec.addQuery('document_id', RecordID);
appRec.query();

var allComments = "";

while (appRec.next()) {
    var comments = appRec.comments.getJournalEntry(1);
    var name = appRec.approver.name.getDisplayValue();
    allComments += "Case is Approved by " + name + '\n' + comments + '\n';
}

return allComments;

 

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket