The CreatorCon Call for Content is officially open! Get started here.

Show state 'Waiting for Approval' and approver name for which It is pending in service portal

Nikita35
Kilo Guru

hi 

I already see that on RITM the state is visible as "Waiting for Approval"

but how do I add approvers for which it is pending ?

In which widget shall I do the modifications ?

Please help if anybody has implemented the same and has code template.

7 REPLIES 7

Nikita35
Kilo Guru

I created new widget using below code

https://community.servicenow.com/community?id=community_question&sys_id=fbac40bbdbba5304a8562926ca96...

but it shows me nothing in the approvals.

There exists the approver in the ticket.

Can anybody help what can be missing?

 

 

 

Nikita35
Kilo Guru

I created new widget using code in the PDF.

This gives me only one approver even if it has multiple approvers. 

How do I resolve that ? Can anybody help ?

Dustin Taber1
Tera Expert

Building on Premer's idea, I tried this out for myself. I had a bit of trial and error to get through but I got it working to populate the data on the Item field. 

I created a custom field on the requested_item table called "u_waiting_approval_from" as instructed by Premer. This is a simple string field, but I bumped up the characters allowed to 80 in the dictionary. This will allow me to show multiple approver names on a single line. 40 wasn't enough, the names were getting cut out.

 

I then created a business rule on the sysapproval_approver table as instructed by Premer. 

When to run: "After" Insert & Update.

No Conditions, No Actions.

Advanced:

(function executeRule(current, previous /*null when async*/) {

		var docID = current.sysapproval;  //works better with manual approver adds
		var names = "";
		
		var approvals = new GlideRecord('sysapproval_approver');  //setup query on the approval table
		approvals.addQuery('sysapproval', docID);  //filter all approvals that have matching sysapproval values
		approvals.addQuery('state', 'Requested');  //filter those for a requested state
		approvals.query();  //run the query
		
		while(approvals.next())  //loop through the results
		{
			names += approvals.approver.name + " ";  //stack results into the variable
		}
	
		var itm = new GlideRecord('sc_req_item');  //setup query on requested items table
		itm.addQuery('request', docID);  //find all items that have a matching 'request' field to the 'sysapproval' value
		itm.query();  //run the query

		if(itm.hasNext())  //if results found
		{
			while(itm.next())  //loop through the results
			{
				itm.u_waiting_approval_from = "";  //clear previous entry
				itm.u_waiting_approval_from = names;  //add approver(s)
				itm.update();  //update

			}  //end while
			
		}  //end if
	
})(current, previous);

To illustrate this I've included some photos.

 Edit - It may be worth noting that my approvals are per the Request, not per item.