- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2024 02:42 AM
I have configured a notification to be sent after a request is created. In the request, several RITMs (Requested Items) are generated. If more than one RITM has the same "Requested For" user, I need to display the user's name in the email. If the "Requested For" users are different, I will not display the name and will instead show it under each request.
Example:
In the screenshot above, I can display cases where the "Requested For" users are different. However, I need guidance on configuring the display when the "Requested For" users are the same.
Email script
var count = 0;
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.sys_id);
gr.query();
var request = current.number.getDisplayValue();
var requested_by = current.opened_by.getDisplayValue();
var requested_for = current.requested_for.getDisplayValue();
var requestUrl = '<a href="' + gs.getProperty('glide.servlet.uri') + 'spalcoa?id=order_status&table=sc_request&sys_id=' + current.sys_id + '">' + request + '</a>';
var sportalLink = '<a href="' + gs.getProperty('glide.servlet.uri') + 'sp">' + 'Service Portal' + '</a>';
template.print('<br>');
template.print('<div><span style="font-family: arial; font-size: 11pt;">Request ticket ' + request + ' has been created in ServiceNow.</span></div>');
template.print('<br>');
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>Ticket Details</b></span></div>');
template.print('<div class="x_MsoNormal" style="text-align: center;" align="center"><hr align="center" size="2" width="100%" /></div>');
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>Request Number: ' + requestUrl + '</b></span></div>');
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>Requested By: </b>' + requested_by + '</span></div>');
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>Requested For: </b>' + requested_for + '</span></div>');
template.print('<br>');
if (gr.getRowCount() > 1) {
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>Requested Item(s)</b></span></div>');
template.print('<div class="x_MsoNormal" style="text-align: center;" align="center"><hr align="center" size="2" width="100%" /></div>');
while (gr.next()) {
var ritmUrl = '<a href="' + gs.getProperty('glide.servlet.uri') + 'spalcoa?id=ticket&table=sc_req_item&sys_id=' + gr.sys_id + '">' + gr.number + '</a>';
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>RITM Number: ' + ritmUrl + '</b></span></div>');
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>Requested For: </b>' + gr.requested_for.getDisplayValue() + '</span></div>');
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>Short Description: </b>' + gr.short_description + '</span></div>');
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>Description: </b>' + gr.description + '</span></div>');
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>Stage: </b>' + gr.stage.getDisplayValue() + '</span></div>');
template.print('<br>');
}
} else {
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>Requested Item</b></span></div>');
template.print('<div class="x_MsoNormal" style="text-align: center;" align="center"><hr align="center" size="2" width="100%" /></div>');
if (gr.next()) {
var ritmUrl = '<a href="' + gs.getProperty('glide.servlet.uri') + 'spalcoa?id=ticket&table=sc_req_item&sys_id=' + gr.sys_id + '">' + gr.number + '</a>';
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>RITM Number: ' + ritmUrl + '</b></span></div>');
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>Short Description: </b>' + gr.short_description + '</span></div>');
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>Description: </b>' + gr.description + '</span></div>');
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>Stage: </b>' + gr.stage.getDisplayValue() + '</span></div>');
template.print('<br>');
}
}
template.print('<br>');
template.print('<div><span style="font-family: arial; font-size: 11pt;">To track the progress of your tickets, please go to the ' + sportalLink + '</span></div>');
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2024 05:10 AM
Hi @deepika adimu ,
Try the following logic:
- Store the "Requested For" values in an array.
- Check if the elements in the array are identical.
- If they are the same, do not display the name.
- If they are different, display the respective names.
This approach will help ensure that the "Requested For" names are displayed correctly based on their uniqueness.
var gr1 = new GlideRecord('sc_req_item');
gr1.addQuery('request', current.sys_id);
gr1.query();
var checkReq = [];
while (gr1.next()) {
checkReq.push(gr1.requested_for.name.toString());
}
if (checkReq[0] != checkReq[1]) {
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>Requested For: </b>' + gr.requested_for.getDisplayValue() + '</span></div>');
}
If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2024 02:47 AM
you need to check Requested for for each RITM and create the logic.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2024 05:10 AM
Hi @deepika adimu ,
Try the following logic:
- Store the "Requested For" values in an array.
- Check if the elements in the array are identical.
- If they are the same, do not display the name.
- If they are different, display the respective names.
This approach will help ensure that the "Requested For" names are displayed correctly based on their uniqueness.
var gr1 = new GlideRecord('sc_req_item');
gr1.addQuery('request', current.sys_id);
gr1.query();
var checkReq = [];
while (gr1.next()) {
checkReq.push(gr1.requested_for.name.toString());
}
if (checkReq[0] != checkReq[1]) {
template.print('<div><span style="font-family: arial; font-size: 11pt;"><b>Requested For: </b>' + gr.requested_for.getDisplayValue() + '</span></div>');
}
If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.