Customizing Approval Notification

Manoj82
Kilo Expert

Hi,

I need help in customizing our existing Approval notifications on Requests. In our current system(Asset mgmt) when a user request let's say 2 items , our approval notifications will provide the details of each and every Requested item(RITM) as shown below:

find_real_file.png

Sometimes, our requests that have 100 request items and the notification looks very clumsy. I am trying to update this into the following format which consists of a table for all the Requested items(RITMs)

find_real_file.png

 

Can someone please help me how to achieve this kind of notification so that  all the items are in a table. 

Regards,
Manoj

 

1 ACCEPTED SOLUTION

Can you change it to 

 

Short Description: ${sysapproval.short_description}
Priority: ${sysapproval.priority}
Requested For: ${sysapproval.requested_for}
Requested By: ${sysapproval.opened_by}
Total Price: ${sysapproval.price}
<hr/>
<mail_script>
var item = new GlideRecord("sc_req_item");
item.addQuery("request", current.sysapproval);
item.query();


if (item.getRowCount() > 0) {
template.print('<table border="1"><th colspan="4" style="text-align:center">Summary of Requested items</th>');
while(item.next()) {
template.print('<tr><th>'item.number + '</th><th>' + item.quantity + '</th><th>' + item.cat_item.getDisplayValue() + '</th><th>' + item.price.getDisplayValue() + '</th></tr>')

}
template.print('</table>');
}

</mail_script>

 

 

 

if that doesnt work, try this as well 

Short Description: ${sysapproval.short_description}
Priority: ${sysapproval.priority}
Requested For: ${sysapproval.requested_for}
Requested By: ${sysapproval.opened_by}
Total Price: ${sysapproval.price}
<hr/>
<mail_script>
var item = new GlideRecord("sc_req_item");
item.addQuery("request", current.sysapproval);
item.query();


if (item.getRowCount() > 0) {
template.print('<table border="1">'); 
while(item.next()) {
template.print('<tr><th>'item.number + '</th><th>' + item.quantity + '</th><th>' + item.cat_item.getDisplayValue() + '</th><th>' + item.price.getDisplayValue() + '</th></tr>')

}
template.print('</table>');
}

</mail_script>


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

View solution in original post

6 REPLIES 6

SanjivMeher
Kilo Patron
Kilo Patron

You can definitely achieve this. Below thread should help

 

https://community.servicenow.com/community?id=community_question&sys_id=21d08f65db98dbc01dcaf3231f96...

 

Looks at the comment below. script marked in bold are important which you can use

 

Hi Ramesh,


 


Please try with the below code:


 


var baseUrl = gs.getProperty("glide.servlet.uri");


var gr = new GlideRecord("change_request");


gr.addEncodedQuery("active=true");


gr.query();


if (gr.getRowCount() > 0) {


template.print('<table border="1"><th colspan="4" style="text-align:center">Change Request Report</th>');


    while (gr.next()) {


        template.print('<tr><th><a href=' + baseUrl + gr.getLink() + '>' + gr.getValue('number') + '</a></th><th>' + gr.short_description +'</th><th>'+           gr.getDisplayValue('state') + '</th><th>'+ gr.getDisplayValue('type') +'</th></tr>');


}


template.print('</table>');


}


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

Manoj82
Kilo Expert

Hi Sanjiv,

I have updated my Email template (request.itil.approve.role) with the script as mentioned above. But somehow it is still not working as intended,

Short Description: ${sysapproval.short_description}
Priority: ${sysapproval.priority}
Requested For: ${sysapproval.requested_for}
Requested By: ${sysapproval.opened_by}
Total Price: ${sysapproval.price}
<hr/>
<mail_script>
var item = new GlideRecord("sc_req_item");
item.addQuery("request", current.sysapproval);
item.query();
if (item.getRowCount() > 0) {
template.print('<table border="1"><th colspan="4" style="text-align:center">Summary of Requested items</th>');
while(item.next()) {
template.print('<tr><th>'item.number + '</th><th>' + item.quantity + '</th><th>' + item.cat_item.getDisplayValue() + '</th><th>' + item.price.getDisplayValue() + '</th></tr>')

}
template.print('/table');
}

</mail_script>

The output of the preview is attached below.

Regards,
Manoj

Can you change it to 

 

Short Description: ${sysapproval.short_description}
Priority: ${sysapproval.priority}
Requested For: ${sysapproval.requested_for}
Requested By: ${sysapproval.opened_by}
Total Price: ${sysapproval.price}
<hr/>
<mail_script>
var item = new GlideRecord("sc_req_item");
item.addQuery("request", current.sysapproval);
item.query();


if (item.getRowCount() > 0) {
template.print('<table border="1"><th colspan="4" style="text-align:center">Summary of Requested items</th>');
while(item.next()) {
template.print('<tr><th>'item.number + '</th><th>' + item.quantity + '</th><th>' + item.cat_item.getDisplayValue() + '</th><th>' + item.price.getDisplayValue() + '</th></tr>')

}
template.print('</table>');
}

</mail_script>

 

 

 

if that doesnt work, try this as well 

Short Description: ${sysapproval.short_description}
Priority: ${sysapproval.priority}
Requested For: ${sysapproval.requested_for}
Requested By: ${sysapproval.opened_by}
Total Price: ${sysapproval.price}
<hr/>
<mail_script>
var item = new GlideRecord("sc_req_item");
item.addQuery("request", current.sysapproval);
item.query();


if (item.getRowCount() > 0) {
template.print('<table border="1">'); 
while(item.next()) {
template.print('<tr><th>'item.number + '</th><th>' + item.quantity + '</th><th>' + item.cat_item.getDisplayValue() + '</th><th>' + item.price.getDisplayValue() + '</th></tr>')

}
template.print('</table>');
}

</mail_script>


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

Manoj82
Kilo Expert

Hi Sanjiv,

It worked, few chnages have to be done for the script as item.number will not work for the html script, so I used item.getValue.

Also now after chnaging the script I have another question: 

find_real_file.png

As shown in the image above each cell is divided individually and I am looking to combine them as shown below:

 

find_real_file.png

 

Do you have any idea?

Regards,
Manoj