catalog item variables in sc_task notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2013 09:17 AM
Hello,
I have an email notification that fires for the event 'sc_task.assigned.to.group'. It is on the sc_task table. I have a script (below) that I want to have show the variables from the catalog item that this task is attached to (the catalog task is created from the catalog item workflow). It DOES return variables, but it returns ALL of them. ALL of the variables for every single open request on the dev server is in the notification email. That makes the email a bit...long. Is there a way to only get the variables for the item that the task is related to? I first tried a glide query for the table 'sc_req_item', but got the same result. I was hoping that using sc_task would fix the issue but it didn't. Any suggestions?
<mail_script> var itemRec = new GlideRecord("sc_task"); itemRec.addQuery("task", current.sysapproval); itemRec.query(); while (itemRec.next()) { for (key in itemRec.variables) { var v = itemRec.variables[key]; if(v.getGlideObject().getQuestion().getLabel() != '') { template.space(4); template.print(' ' + v.getGlideObject().getQuestion().getLabel() + " = " + v.getDisplayValue() + "\n"); } } } </mail_script>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2013 09:38 AM
This line is NOT referring to anything:
task and sysapproval are NOT fields on the sc_task table, so it is returning all variables:
itemRec.addQuery("task", current.sysapproval);
Try this (script taken from the 'request.itil.approve.role' email template and modified):
var item = new GlideRecord("sc_req_item");
item.addQuery("sys_id",current.request_item );
item.query();
while(item.next()) {
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(item.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i=0; i < vs.size(); i++) {
if(vs.get(i).getLabel() != '') {
template.space(4);
template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2013 09:55 AM
Thanks! Unfortunately that didn't return anything at all. Nothing shows up in the email after "Description: ${description}" except the watermark. Here is the full notification in case I'm missing something:
Short Description: ${short_description}
Assignment group: ${assignment_group}
Click here to view Task: ${URI_REF}
Click here to view Requested Item: ${request_item.URI_REF}
Requested For:${sc_task.request_item.request.requested_for}
Due date: ${due_date}
Description: ${description}
<mail_script>
var item = new GlideRecord("sc_req_item");
item.addQuery("sys_id",current.request_item );
item.query();
while(item.next()) {
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(item.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i=0; i < vs.size(); i++) {
if(vs.get(i).getLabel() != '') {
template.space(4);
template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");
}
}
}
</mail_script>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2018 02:06 PM
That worked for me.
On Kingston.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2013 10:06 AM
Is your Requested For showing up? I would think that would need to be:
Requested For:${request_item.request.requested_for}