Approver comments on Task

Brian Lancaster
Tera Sage

I have a request to make it so that the approvers comments they put in the comments section.   How to I go about placing the approver comments into the task?

1 ACCEPTED SOLUTION

This is what our Approval Events (Task) business rule look like.   It was modified by the company that helped us setup ServiceNow.   How ever even if you want to use a group for approve you still have to use the approval user task in the workflow as that one works for both individuals and groups.   That is the only time that approval comments show up.



function checkRequest() {
      var task = current.sysapproval.sys_class_name;
      return (task == 'sc_request');
}


function checkSCTask() {
      var task = current.sysapproval.sys_class_name;
      return (task == 'sc_task');
}


var isRequest = checkRequest();
var isSCTask = checkSCTask();


if (current.state.changes() && current.state=='cancelled') {
      var event = "approval.cancelled";
      if (isRequest)
              event = "request.approval.cancelled";
      else if (isSCTask)
              event = "sc_task.approval.cancelled";
     
      gs.eventQueue(event, current, gs.getUserID(), gs.getUserName());
}


if (current.state.changes() && current.state=='requested') {
      var event = "approval.inserted";
      if (isRequest)
              event = "request.approval.inserted";
      else if (isSCTask)
              event = "sc_task.approval.inserted";
     
      gs.eventQueue(event, current, gs.getUserID(), gs.getUserName());
      updateTask(current, current.approver.getDisplayValue() + " requested to approve task");
}


if (current.state.changes() && current.state=='rejected') {
      var event = "approval.rejected";
      if (isRequest)
              event = "request.approval.rejected";
      else if (isSCTask)
              event = "sc_task.approval.rejected";
     
      gs.eventQueue(event, current, current.state, previous.state);
      updateTask(current, gs.getUserDisplayName()+ " rejected the task.", current.comments.getJournalEntry(1));
      notifyMyFriends(current);
}


if (current.state.changes() && current.state=='approved') {


      updateTask(current, gs.getUserDisplayName() + " approved the task.", current.comments.getJournalEntry(1));
}


function notifyMyFriends(me) {
      var friends = new GlideRecord('sysapproval_approver');
      friends.addQuery('sysapproval', me.sysapproval);
      friends.query();
      while(friends.next()) {
              if (friends.approver.toString() != me.approver.toString()) {
                      gs.eventQueue("approval.rejected.by.other", me, friends.approver);
              }
      }
}


function updateTask(me, journal, comments) {
      // if this is for a group approval, don't log this user action since the Group Approval Activity will handle the logging
    // if (!current.group.nil())
        //     return;
     
      // only log the user approval activity for workflows when specifically turned on
      // otherwise, we spam the approval history log when it is almost never desired to track via the approval history journal field
      var isWorkflow = !current.wf_activity.nil();
      if (isWorkflow && (gs.getProperty("glide.workflow.user_approval_history") != "true"))
              return;
     
      if (comments)
  journal += " Comments: " + comments;
     
      var task = new GlideRecord('task');
      if (task.get(me.sysapproval)) {
              if (isWorkflow)
                      task.setWorkflow(false);
             
              task.approval_history.setJournalEntry(journal);
              task.update();
      }
}



View solution in original post

44 REPLIES 44

I'm maybe wrong but I understood the important part was the "comments" itself (like "I rejected the item request because ....").



That is why I proposed to push the comments to the "task" from the approval, as it makes senses and it's the faster way (I think) for someone new on ServiceNow.



Regards,


Looking at the business rule it should do it:


if (current.state.changes() && current.state=='approved') {
   updateTask(current, current.approver.getDisplayValue() + " approved the task.", current.comments);
}


And the function "updateTask" is basically getting the task for this approval request and adds the text to the approval_history field.


As far as I can tell the Business Rule is unchanged and out-of-box.


I double checked his with a demo instance and we have the same script.



However, the script also checks a system property — maybe that is set to "false" in your case?


glide.workflow.user_approval_history



https://demo022.service-now.com/nav_to.do?uri=sys_script.do?sys_id=aea34678c61122710151b1b7fdf65762




Also I tried it and even though the comment is added to the field "approval_history" it shows up as a "Additional Comments" entry … not sure why but didn't do any deep digging yet either


What is the name of the business rule.   I don't see that code in my business rules.   At least not the ones on the approval table as mentioned before.


It is called "Approval Events (Task)"



Did you follow the link I provided?


Ok found it but it doesn't seem to be working or maybe I'm just adding it incorrectly to the activity log.   I right click and did personalize Activities and added Approval history but no additional info is showing in my activity logs.