Approval Comment copy

Mike Cumbee
Giga Expert

I have been struggling with a Change Request workflow script.   The customer wants to see the Approval Comments on the main page of the the Change Request after the Approver has Approved or Rejected it.   I have searched through the community scripts and seen several Business Rules examples that have not worked (for me), for instance:

Copy contents of approval comments into change request comments

Approver comments on Task

How can we have rejection comments appear in the actual change notes?

This is on a Test server on site using Geneva.   I have some development experience with JavaScript, ASP.NET (VB and C#) and some MS SQL.   Fairly new to ServiceNow.

The goal is to place Approval Comments on the Change Request Page - or even in the Task that comes directly after the approval.   I would prefer a WorkFlow Script, but Business Rule is fine.

Here's the Business Rule setup and script:

find_real_file.png

find_real_file.png

In this, you can see I have:   app.comments.toString() as well as getJournalEntry(1).   The result in the log is BR app.comments: undefined/undefined

using current.comments produces Current.comments: /

It seems to me that I am grabbing the wrong record (there seems to be something there) to see the Approver's Comments.   I have also tried some script in the WorkFlow in a Run Script after the Approval and in the Approval itself.   Using the code above, the gr.update causes an error and the only comments I seem to be able to see are the ones that were created on the Change Request form (main page).

Any help would be appreciated, especially how to locate and navigate the ServiceNow tables and fields.

MC

1 ACCEPTED SOLUTION

Fernando Dunn
Mega Expert

I thought the defualt Approval Events (Task) business rule should already take care of this but here is a basic script for an After business rule on the sysapproval_approver table:



var chg = new GlideRecord('change_request');


chg.get(current.sysapproval);


chg.comments = current.comments.getJournalEntry(1);


chg.update();


View solution in original post

3 REPLIES 3

Fernando Dunn
Mega Expert

I thought the defualt Approval Events (Task) business rule should already take care of this but here is a basic script for an After business rule on the sysapproval_approver table:



var chg = new GlideRecord('change_request');


chg.get(current.sysapproval);


chg.comments = current.comments.getJournalEntry(1);


chg.update();


Yes!   Just had someone look over my shoulder here and we got it up!



  1. var gr = new GlideRecord('change_request');
  2. gr.get(current.sysapproval);
  3. gr.comments = current.comments.toString();
  4. gr.update();


As for the Approval Events (Task).   It was not moving the comments to the Activity area - and I did make sure to turn on Additional Comments.



getJournalEntry(#) starts with 1 and not 0?



Thank you


Glad to help, Mike!



For getJournalEntry(), -1 is for all entries and 1 is for the most recent entry. I don't see 0 is an option.


GlideElement - ServiceNow Wiki



I believe getJournalEntry only works in an After rule because it is pulling the already saved string from the journal, whereas (I believe) current.comments.toString() only works in a Before rule or client script. So that is probably something to keep in mind.