In this series, I would like to share the solutions that are missing in Service Portal. Today I would to discuss about how to make rejection comments mandatory in Service Portal.

 

Approvals in ServiceNow are handled either via emails or through an approval record. One of the significant reasons to use approvals via form is the ability to capture comments when rejecting a record. In a form view there is an OOB UI policy Comments mandatory on rejection, that makes comments field mandatory while rejecting a record.

 

When I initially started playing with Portal, I did not find a way to capture comments in OOB approval widgets. So I cloned the OOB Approval info widget and added a new text box

<textarea ng-model="c.data.comment" style="color: grey; width: 100%; margin-top: .5em;" placeholder="Rejection Comments" class="form-control" rows="5"></textarea>

 

Below  is the screenshot of comments box

 

In order to make the comments field required while rejecting, first validate whether it is empty or not. If it is then stop the approval process.

After adding couple lines in server and client controller I'm able stop the rejection when the comments are NULL and an alert box will pop out as shown in the image below.

 

Here is the code that has to be updated in server and client controller blocks of a cloned widget.

 

Server Code

 

if (input.comment){
     gr.comments = input.comment;
     gr.update();
}

 

Client Controller

 

c.action = function(state) {

     if( (c.data.comment ==  undefined || c.data.comment ==  '' )&& state == 'rejected'){
          $window.alert('Rejection Comments cannot be empty');
          return false;

     }
     c.data.op = state;
     c.data.state = state;
     c.server.update();
}

 

 

 

Please find the attached XML of updated Approval info widget.

 

 

Blogs in this series

Portal diaries: Service Portal – Approval Summarizer in Portal

Portal diaries: Service Portal – Multiple Catalogs (Part 1)