- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2022 03:01 AM
Hi All,
My requirement is to create one notification for 2 different catalogs and notification should contain variable of particular catalog item.For example i have 2 catalogs:
Catalog 1(Server Request ) have fields "Server 1,Server 2 and Server 3"
Catalog 2(database Request ) have field "database 1,database 2 and database 3"
notifications should be triggered once RITM get created and this notification should contains "Server 1 and Server 2" if Catalog 1 gets submitted and "database 1,database 2" should be populated it Catalog 2 gets submitted.
how we can achieve this with one email script?
If any idea please share with me.
Thanks in Advance.
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2022 05:09 AM
Hi,
You can write the email script and call it in your notification.
Name = "multiple_cat_item_example"
(function runMailScript(current, template, email, email_action, event) {
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('sys_id', current.sys_id);
gr.query();
if (gr.next())
{
if (gr.cat_item == 'sys_id_of_catalog1') {
template.print(current.variables.server_1);
template.print(current.variables.server_2);
template.print(current.variables.server_3);
email.setSubject("For catalog item 1");
}
else if (gr.cat_item == 'sys_id_of_catalog2') {
template.print(current.variables.database1);
template.print(current.variables.database2);
template.print(current.variables.database3);
email.setSubject("For catalog item 2");
}
}
})(current, template, email, email_action, event);
})(current, template, email, email_action, event);
Now call the email script in the notification What it will Contain >> Message HTML
${mail_script:multiple_cat_item_example}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2022 07:07 AM
Hi Ankur ,
we same requirement (populating variables based on catalog) but this time its on when approval is getting triggered.
so this my notification is on approval table and my mail script should do glide on "sysapproval_approver" right?
can you please help me with the query? how can we access variable from below code?
var grA= new GlideRecord('sysapproval_approver');
grA.addQuery('sys_id', current.sys_id);
grA.query();
while (grA.next()) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id', grA.sysapproval);
ritm.query();
while (ritm.next()) {
if (ritm.sys_id == 'XXXXXXXXXXXXXXXXXXXXX') {
template.print("Test: " + current.variables.category1);//not sure how can we access variable from here
email.setSubject("For catalog item 1");
} else if (ritm.sys_id == 'YYYYYYYYYYYYYYYYYYYYYYYYY') {
template.print("Test: " + current.variables.category1);
email.setSubject("For catalog item 1 " + current.number);
}
}
}
Thank you in Advance!