- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2024 01:33 PM
Had a look and this seems to have been an issue many have had.
I'm currently using a mail script which is working for all other task records (sc_task and inc) when they are assigned to an ITIL user to work through, but records that were created via a record producer come up empty.
The actual fields are being utilized such as short_description which is puzzling me since I'd think they would pull like normal.
Any help would be much appreciated.
Script Below:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
for (var key in current.variables)
{
var v = current.variables[key];
if(v && v.getDisplayValue() != 'false')
{
template.print(v.getGlideObject().getQuestion().getLabel() + " " + v.getDisplayValue() + " <br>");
}
}
template.print('<hr/>');
})(current, template, email, email_action, event);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 06:56 AM
Thanks for confirmation.
Now if you want to bring in RITM's variable on sc_task notification then use this in email script and it will work
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var ritmObj = current.request_item.getRefRecord();
var variables = ritmObj.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/>");
}
}
template.print('<hr/>');
})(current, template, email, email_action, event);
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-04-2024 07:30 PM
the email script is on same table?
try this
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
template.print('RITM Variables: <br/>');
var variables = current.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);
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-05-2024 05:55 AM
Hi @Ankur Bawiskar,
This unfortunately didn't work for any records created via the record producer. To answer your question, the email notification is on sc_task and the email script is on global application.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 06:35 AM
did you check question_answer table got populated when you submitted the record producer?
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-05-2024 06:40 AM
it worked for me.
1) I submitted record producer with target table as incident and it added records to question_answer table
2) I ran the script and it printed the variable values
var rec = new GlideRecord('incident');
rec.get('7818dce1db5e5e50727ee7dcd396196e');
var variables = rec.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 != ''){
gs.info(' ' + label + " = " + value + "<br/>");
}
}
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