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

That's strange because you are querying only 'requested' approvals. You should not get any 'no longer required' there, because that's also a state on the approval record. What is the trigger on your BR? Can you make make it 'approval = requested' it it's not already?


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

I agree, but it leaves the approver uncleared, as in the screenshot.

find_real_file.png

 

My BR trigger is set up this way.

find_real_file.png

The BR now runs after you update the RITM. Can you make it on display? Because if you have a flow creating a first and second approval, your RITM isn't going to update. It stays on awaiting approval.


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

You are right!
My requirement was achieved by making the BR trigger asynchronous or before the update.

Thank you for your kindness and patience!

No problem. Glad it worked!


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