Need to list all approvers if possible or count in email message body

vinnus
Tera Contributor

can all involved approvers being listed in message body or only the approval recipient? or can show count of total approver?

 

vinnus_0-1714238202466.png

 

2 ACCEPTED SOLUTIONS

Community Alums
Not applicable

Hi @vinnus ,

Look I tried your problem in my PDI and it works for me I'm adding images for reference 

I created before BR on sc_req_item and added below code 

 

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

	// Add your code here
	var appArr = []
	var gr = new GlideRecord('sysapproval_approver');
	gr.addQuery('sysapproval', current.sys_id);
	gr.query();
	while(gr.next()){
		appArr.push(gr.approver.getDisplayValue());
	}
	gs.eventQueue('send.approval.notificatio', current, current.number, appArr);

})(current, previous);

 

SarthakKashya2_1-1714239898449.png

 

Than I create event at I called in the script 

SarthakKashya2_2-1714239930620.png

 

Than in email notification I called the parm 1 and parm 2 

SarthakKashya2_3-1714239969108.png

 

Below is result 

 

SarthakKashya2_0-1714239829245.png

 

Note: If you want to call the email scirpt you can also use the below code 

In notificaition you can call like this - ${mail_script:scriptName}

Add below code 

 

 

Result of email script 

Notification

SarthakKashya2_0-1714241086597.png

Email Script

SarthakKashya2_1-1714241111266.png

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    // Add your code here
    var appArr = []
	gs.log('Hree in email script = ' + current.sys_id)
    var gr = new GlideRecord('sysapproval_approver');
    gr.addQuery('sysapproval', current.sys_id);
    gr.query();
    while (gr.next()) {
        appArr.push(gr.approver.getDisplayValue());
    }
	template.print(appArr);

})(current, template, email, email_action, event);

Output: 

SarthakKashya2_2-1714241164114.png

 

 

 

 

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

 

 

 

 

View solution in original post

Ayushi12
Mega Sage

Hi @vinnus,
You can write an email script to get all approvers in the email body. You can refer to the below sample code.

// Add your code here
	var appArr = []
	var gr = new GlideRecord('sysapproval_approver');
	gr.addQuery('sysapproval', current.sys_id);
	gr.query();
	while(gr.next()){
		appArr.push(gr.approver.getDisplayValue());
	}

 

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

6 REPLIES 6

Community Alums
Not applicable

Hi @vinnus ,

This is possible to add all the approval in email body, you just need to create a event and in the parm1 or parm2 you can send the array of approvals and trigger the email notification when event is triggered. In email body you can send all the approvals like${event.parm1}.

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

Community Alums
Not applicable

Hi @vinnus ,

Look I tried your problem in my PDI and it works for me I'm adding images for reference 

I created before BR on sc_req_item and added below code 

 

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

	// Add your code here
	var appArr = []
	var gr = new GlideRecord('sysapproval_approver');
	gr.addQuery('sysapproval', current.sys_id);
	gr.query();
	while(gr.next()){
		appArr.push(gr.approver.getDisplayValue());
	}
	gs.eventQueue('send.approval.notificatio', current, current.number, appArr);

})(current, previous);

 

SarthakKashya2_1-1714239898449.png

 

Than I create event at I called in the script 

SarthakKashya2_2-1714239930620.png

 

Than in email notification I called the parm 1 and parm 2 

SarthakKashya2_3-1714239969108.png

 

Below is result 

 

SarthakKashya2_0-1714239829245.png

 

Note: If you want to call the email scirpt you can also use the below code 

In notificaition you can call like this - ${mail_script:scriptName}

Add below code 

 

 

Result of email script 

Notification

SarthakKashya2_0-1714241086597.png

Email Script

SarthakKashya2_1-1714241111266.png

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    // Add your code here
    var appArr = []
	gs.log('Hree in email script = ' + current.sys_id)
    var gr = new GlideRecord('sysapproval_approver');
    gr.addQuery('sysapproval', current.sys_id);
    gr.query();
    while (gr.next()) {
        appArr.push(gr.approver.getDisplayValue());
    }
	template.print(appArr);

})(current, template, email, email_action, event);

Output: 

SarthakKashya2_2-1714241164114.png

 

 

 

 

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

 

 

 

 

Hi Sarthak, Thanks for the help.

Need to populate the case record field value in Sys approval table notification email Subject.

Field name: Process 

Case table: dfit_case

Community Alums
Not applicable

Hi @vinnus ,

You can add this in Subject - Process : ${process(backend_value)}

SarthakKashyap_0-1715066158313.png

 

Result

SarthakKashyap_1-1715066184085.png

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak