How can I display only current approvers on ticket page of Service Portal?

Kou1
Tera Expert

Hi everyone!

I was referring to this post to try to get the approvers to show up on the Service Portal ticket page.
https://community.servicenow.com/community?id=community_question&sys_id=5ff9520bdb518d10019ac2230596...

I was able to display the approvers.
However, if, for example, approval record B is created after approval record A is approved, the approvers for the previous record are still displayed and the approvers for the next record are added to the list.

In this case, when approval record B is created, we want only that approver to be displayed.

I have added code to the business rule to initialize the field for display to solve this problem, but it does not work.

How can I achieve my requirements?

 

Table Name: sysapproval_approver
When: After Insert

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

    var gr = new GlideRecord('sc_req_item');
    gr.addQuery('sys_id', current.sysapproval);
    gr.query();

	// Show current approvers on glide_list field "u_current_approvers"
    if (gr.u_current_approvers == '') {
        if (gr.next()) {
            gr.u_current_approvers += ',' + current.approver.toString();
        }

	// Initialize if there is a value in glide_list field "u_current_approvers"
    } else {
        gr.u_current_approvers = '';

        if (gr.next()) {
            gr.u_current_approvers += ',' + current.approver.toString();
        }

    }

    gr.update();

})(current, previous);

 

Best Regards,
Kou

1 ACCEPTED SOLUTION

Can you turn the logic around and create this BR on the sc_req_item table? 

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

	current.u_current_approvers = '';
	
    var appr = new GlideRecord('sysapproval_approver');
	appr.addQuery('sysapproval',current.getUniqueValue());
	appr.addQuery('state','requested')
    appr.query();
	while(appr.next()){
		current.u_current_approvers += appr.approver.toString() + ', ';
		current.update();
	}

})(current, previous);

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

10 REPLIES 10

Mark Manders
Mega Patron

Is your issue resolved? If so, please close the question and if any answer helped or was correct, mark it as such, since that will help others when looking for the same. If your issue isn’t resolved, please let us know what in the provided answers didn’t work and what you still need assistance with.

Mark


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark