Need to fetch Variable value into the notification.

Priya Gautum
Kilo Guru

Hi All

I want to fetch the variable input into the Notification(in sc_task table), I tried to achieve it through Email script but its is not fetching.

I wrote my notification sc_task table. & my varaible name is "product_profile" .

(function runMailScript(current, template, email, email_action, event) {


var item = new GlideRecord("sc_task");

item.addQuery("sys_id", current.sys_id);
item.query();

while(item.next()) {

var catalogItem = item.number + ': ' + current.cat_item.getDisplayValue();


var misc = item.variables.product_profile;

template.print(catalogItem + "<br/> Field: " + misc);


}

})(current, template, email, email_action, event);

 

Regards,

Priya

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Priya,

I could see the script and some modification to be done; I assume the email notification runs on sc_task table

the item object in your script is of sc_task and sc_task has 1 field request_item which stores RITM information so wherever you have used that I have dot walked upto that level; so you need to go 1 level deeper to get the information

also used if condition since there would be only 1 record with that sys_id in sc_task table

(function runMailScript(current, template, email, email_action, event) {

var item = new GlideRecord("sc_task");
item.addQuery("sys_id", current.sys_id);
item.query();
if(item.next()) {
var catalogItem = item.request_item.number + ': ' + item.request_item.cat_item.getDisplayValue();
var misc = item.request_item.variables.product_profile;
template.print(catalogItem + "<br/> Field: " + misc);
}

})(current, template, email, email_action, event);

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5