How to add comments in approval from Workflow activity user approval

Jerin5
Giga Guru

I tried the code: current.sysapproval.comments = "Please provide Approval for "; but I get the error "illegal access to getter method getmessage in class org.mozilla.javascript.rhino exception"

Any thoughts? I don't want to do a BR .

10 REPLIES 10

What I ended up doing is creating a branch. One branch goes to the approval activity, the second branch goes to a run script. Then I joined the 2 activities.

Initially, I had a timer, but I was noticing that the comment would be after the initial notification for approval went, so I removed the timer. 

I also wanted to add the requested_for as part of the comment which is why there are 2 glide record queries. I know it's clunky, but here is the code I used:

//Get value for Requested for user and pass to variable reqFor
var gr_req = new GlideRecord ('sc_req_item');

gr_req.addQuery('sys_id', '168251121b8fc410c19321fcbc4bcbd3');
gr_req.query();
gr_req.next();
var reqFor = gr_req.variables.service_recipient_name.getDisplayValue();

// Get Sys approval record for Supervisor Approval
var gr= new GlideRecord('sysapproval_approver');

gr.addQuery('sysapproval',current.sys_id);
gr.query();

//Add commment to Supervisor approval record
while(gr.next()){
var a = gr.wf_activity.getDisplayValue();
if (a == 'Supervisor Approval'){
gr.comments.setJournalEntry("Please acknowledge that you are approving local admin permissions for " + reqFor, 'admin');
gr.update();
}
}

 

Screenshot of Workflow:

find_real_file.png

Wel... I am listening to @Chuck Tomasi  on JavaScript for ServiceNow for Glide Records (https://www.youtube.com/watch?v=hAm0_-ak65c&list=PL3rNcyAiDYK2_87aRvXEmAyD8M9DARVGK&index=28) and finding how I could have changed the above code...

Using .getValue instead of dot walking and using .get instead of using Query 😞

Kevin133
Tera Expert

Maybe i'm not understanding the requirement but cant you just add ${comments} or ${sysapproval.comments} to your notification template for your approval notification?

I want to add a comment to the approval request. We are doing what you are saying so the existing comments are sent via e-mail to the user. There is a BR set up to add a comment to all approvals using the code current.comments.setJournalEntry("Approval for: " + current.wf_activity.getDisplayValue(), 'admin');

In this case, I want to add a specific message for approval level on 1 Catalog item (not affecting any other catalog items I have). I would like to get the above code to work in the Workflow activity advanced script section of the Workflow approval activity. I did try current.sysapproval_approver.comments.setJournayEntry("xxx"); and it still gives the above error.

My use case: Local admin permissions

1st approval: Supervisor approval 

Approval message to be added: Please approve this request for local admin permissions. Please note (desired verbiage). 

I hope this clarifies my requirement.

Jerin unfortunately there isn't a way to update the generated approval record in the Approval activity itself.  The script block is there to determine the list of approvers and you cannot update a comment in the generated approval(s) itself.  A business rule is the only approach and since you have one already, I would suggest updating it to include this change.