- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 03:33 AM
HI Community,
I have a requirement, in global level the variables of the ritm needs to be present in the request notifications.
This requirement is not specific to single catalog if request is raised from any catalog item then the variables of that catalog needs to be present in the notifications in sc_request (Request ) table.
Note : there is existing notification in request table in that i need to add the ritm variables
How can we achieve this?
Please explain in details as im new to mail script
Thanks in Advance
Suuriya
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 05:17 AM
your notification is on sc_request table?
if yes then try this
var ritmRec = new GlideRecord('sc_req_item');
ritmRec.addQuery('request', current.sys_id);
ritmRec.query();
if (ritmRec.next()) {
var vs = new GlobalServiceCatalogUtil().getVariablesForTask(ritmRec, true);
for (var i = 0; i < vs.length; i++) {
var isMRVS = lbl = vs[i].multi_row + "";
var lbl = vs[i].label + "";
var dis = vs[i].display_value + "";
var visible = vs[i].visible_summary + "";
if (isMRVS == 'true') {
var vArr = vs[i];
template.print("<div>" + "<strong>" + lbl + "</strong></div><hr>");
for (var j = 0; j < vArr.table_variable.length; j++) {
template.print("<div><strong>Row: </strong>" + (j + 1) + "</div>");
var tblArr = vArr.table_variable[j];
for (var k = 0; k < tblArr.length; k++) {
var mrvslbl = tblArr[k].label + "";
var mrvsdis = tblArr[k].display_value + "";
if (mrvslbl != '' && mrvsdis != '' && mrvsdis != 'false') {
template.print("<div>" + "<strong>" + mrvslbl + "</strong>" + ": " + mrvsdis + "</div>");
}
}
template.print("<hr>");
}
} else {
if (lbl != '' && dis != '' && dis != 'false' && visible == 'true') {
template.print("<div>" + "<strong>" + lbl + "</strong>" + ": " + dis + "</div>");
}
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 03:47 AM
Hi @suuriyas,
This is a common question. So as to not reinvent the wheel and give kudos to others who have already provided a solution, check the following link from @Ankur Bawiskar - Kudos.
In case the link breaks and for future use, here's the script:
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
template.print('Variable Summary: <br/>');
var ritm = new GlideRecord('sc_req_item');
ritm.get('request', current.sys_id);
var variables = ritm.variables.getElements();
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
if(label != ''){
template.space(4);
template.print(' ' + label + " = " + value + "<br/>");
}
}
})(current, template, email, email_action, event);
To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 03:55 AM
how are you sending the email?
are you using email script or flow?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 04:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 04:19 AM
HI @Ankur Bawiskar ,
Did some research and find out that in our system there is mail script name kal_requested_item_summary and it is used in approvals table notification it displays all the variables present in the ritm in the approval notifications.
So i tried adding the same in body of my notification like
${mail_script:kal_requested_item_summary}
but it is not working
Can you please let me know what am i missing here
Mail script: