Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Anurag Tripathi
Mega Patron
Mega Patron

Hi Pragati,

Check this if not already, it answers the same issue

https://community.servicenow.com/community?id=community_question&sys_id=31b447e9dbd8dbc01dcaf3231f96...

-Anurag

-Anurag

asifnoor
Kilo Patron

Hi Priya,

Can you print current.sys_id and check if its printing the sc_task sys_id or sc_req_item sys_id. Based on that you can change the query accordingly.

also have you included this script in the notification?

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

Yup, I was doing the same mistake.

I corrected. thanks.

Regards,

Priya