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

Muhammad Khan
Mega Sage

Try after insert business rule on sysapproval_approver table and utilize below script as per your need.

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

	// Add your code here
	var grRITM = new GlideRecord('sc_req_item');
	if(grRITM.get(current.document_id)){
		grRITM.setValue('comments', 'Your request Approver is ' + current.approver.getDisplayValue() + '.');
	}

})(current, previous);

 

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Sushant20 ,

You can Create BR as below on RITM table

GunjanKiratkar_0-1669277888505.png

 

(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.approver).toString();

    }
    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 

 

Thank you for your valuable time highly Appreciated!  its giving the sys id  of the Approver but we want  name of the  Approver additional comment . 

2. Now its giving twice comments once from end user and once is system generated but we want only system generated.

Hi @Sushant20 

You can use 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);
    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