Need help with SC Task email notifications

Joe Taylor
Giga Guru

I am trying to update the email notification "Email assigned to group (sc_task).

All fields are populated except for the "employee_name" which I'm trying to pull from the variables on the SCTASK itself.

 

This is what the body looks like:

     ${mail_script:sctask_subject_line}

     Number: ${number}

     Short description: ${sc_task.short_description}

     Request Requested for: ${request.requested_for}

     Employee Name: ${sc_task.variables.employee_name}

     Assignment group: ${assignment_group}

 

Also, my subject line script isn't pulling any values at all.

This what the subject line looks like right now:  Task undefined - undefined for undefined

This what I have for the script:  

     email.setSubject('Task '+current.sc_task.number.getDisplayValue()+' - '+   current.sc_task_short_description.getDisplayValue()+' for '+current.sc_task.variables.employee_name.getDisplayValue());

 

 

WHAT AM I DOING WRONG?

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

 

Employee Name: ${sc_task.variables.employee_name}


variable is on RITM table. So try using this Employee Name: ${sc_task.request_item.variables.employee_name}


Thakns,
Ashutosh

View solution in original post

7 REPLIES 7

Jaspal Singh
Mega Patron
Mega Patron

Hi Joe,

 

If notification is on sc_task table then you can use below directly.

     email.setSubject('Task '+current.number.getDisplayValue()+' - '+   current.short_description.getDisplayValue()+' for '+current.variables.employee_name.getDisplayValue());

 

No need to use current.sc_task...

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

 

Employee Name: ${sc_task.variables.employee_name}


variable is on RITM table. So try using this Employee Name: ${sc_task.request_item.variables.employee_name}


Thakns,
Ashutosh

Nice Ashutosh. Really helpful. I feel understanding of basic Datastructure of ServiceNow objects is very much essential. Once we visualize & understand the relationships, then we can easily manipulate the data.

Thanks,

Rahul

sachin_namjoshi
Kilo Patron
Kilo Patron

use below email script to get variable information

 

template.print("<b>Summary of Requested items:\n</b>");  


var item = new GlideRecord("sc_req_item");  


if (item.get(current.request_item.sys_id)) {


        template.print(item.number + ": " + item.cat_item.getDisplayValue() + "\n");  


        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).getDisplayValue() != '') {  


                            template.space(4); template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");  


                  }  


        }


}