Trouble with getting sys_id in mail script

Howard Baker
Tera Expert

I have a notification that fires from workflow for a catalog item. I need to look up the due date for catalog task that has already been created for the item, but there seems to be something wrong with how the system is presenting the record values.   The notification fires from an event related to the Requested Item table (sc_req_item).   Here is my mail script:

var sid = "${sys_id}";

var tsk = new GlideRecord('sc_task');

tsk.addQuery('request_item', sid);

tsk.query();

if (tsk.next()) {

    template.print("This is due by " + tsk.due_date.getDisplayValue());

}

This never finds a task record, but if I hard-code the sys_id, it works fine.

Trying to find the problem I tried the following, pasting the actual sys_id of the task record I'm looking for in place of 'the_actual_sys_id':

var sid = "${sys_id}";

template.print("sid: " + sid);

template.print("Length_of_sid: " + sid.length);

template.print("sid == the_actual_sys_id? " + (sid == 'the_actual_sys_id'));

The output for sid is the correct sys_id value.

The output for the length is 17 (should be 32).

The result of the comparison is false.

I think this may be a bug, and I'm going to open a ticket, but I was wondering if anyone else has seen this?

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

You have access to the current object from a mail script so your first line needs to be:



var sid = current.sys_id;



The ${} notation is only available from within the notification itself.


View solution in original post

3 REPLIES 3

Brad Tilton
ServiceNow Employee
ServiceNow Employee

You have access to the current object from a mail script so your first line needs to be:



var sid = current.sys_id;



The ${} notation is only available from within the notification itself.


Howard Baker
Tera Expert

I have tried every possible way I can think of to reference the record values, including ${sys_id}, current.sys_id, current.sys_id.getValue(), current.sys_id.getDisplayValue().   I have tried referencing these directly, as well as assigning to a variable first..   They all return a value that prints correctly, each returns a typeof string, but each result returns a different for length.


I tested this in a dev instance and this worked for me. If it's not working in your dev instance you might want to open a ticket with support.



var sid = current.sys_id;  


var tsk = new GlideRecord('sc_task');  


tsk.addQuery('request_item', sid);  


tsk.query();  


if (tsk.next()) {  


      template.print("This is due by " + tsk.due_date.getDisplayValue());  


}