Adding comments on service portal when the Request is created.

Sushant20
Tera Contributor

When a User Requested something example 'Apple iPhone 13' they have submitted the request. Now if they have any Approval or group Approval. if they have approval on Ritm for the request then it should automatically be added in the comments on the portal so that the end user can see how is the Approval for these Request example your request  Approval is Abel Tuter should be added in the comments.

 

Thank you

1 ACCEPTED SOLUTION

Hi @Sushant20 

Try below :-

(function executeRule(current, previous /*null when async*/ ) { // Add your code here 

    var GroupApp = [];
    var appr = new GlideRecord('sysapproval_approver');
    appr.addEncodedQuery('state=requested^sysapproval=' + current.sys_id);
    appr.query();
    while (appr.next()) {
        GroupApp.push(appr.getDisplayValue('approver')).toString();

    }
    current.setWorkflow(false);
    current.autoSysFields(false);
if(GroupApp.length>0){
    current.comments = 'Approvals For RITM :- \n' + GroupApp;
    current.update();
}
})(current, previous);

Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

9 REPLIES 9

Sushant20_0-1669300102040.png

Its giving me like that second issues is cleared but i'm not getting the name of the current approval... Please have a look

thanks

In first we are getting Abel tutor as expected  but why we are getting twice?

 

Hi @Sushant20 

Try below :-

(function executeRule(current, previous /*null when async*/ ) { // Add your code here 

    var GroupApp = [];
    var appr = new GlideRecord('sysapproval_approver');
    appr.addEncodedQuery('state=requested^sysapproval=' + current.sys_id);
    appr.query();
    while (appr.next()) {
        GroupApp.push(appr.getDisplayValue('approver')).toString();

    }
    current.setWorkflow(false);
    current.autoSysFields(false);
if(GroupApp.length>0){
    current.comments = 'Approvals For RITM :- \n' + GroupApp;
    current.update();
}
})(current, previous);

Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Hi @Gunjan Kiratkar ,

 

what if it need to get approval from sysapproval_group group name to be added in additional comments .. 

 

Many Thanks,

Rajan

Hello @Sushant20 Can you try this below script ?

You BR should be after insert   BR on sysapproval_approver table

 

 

Script:

 

 

 

 

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

	// Add your code here
	var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id',current.sysapproval);
gr.addQuery('state','requested');
gr.query();
if(gr.next());
{

		gr.comments = "Approved By :"+gr.approver.getDisplayValue();
gr.update();
	}

})(current, previous);

 

 

 

Hope this helps 

Mark my answer correct if this helps you 

Thanks