- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2023 07:45 AM
Dear Team,
I am stuck in the requirement, where I have a Catalog Item (Access Change Request) and want to trigger a notification email to some users based on the condition that when in this catalog item, a checkbox variable 'SAP Real Estate' is TRUE (Checked)
Now I don't want to achieve this through Workflow as I do not have a workflow for this catalog item, So I created a Notification and set below 'When to Send' Advanced Condition Script for this particulate catalog item.
'What it will contain'
For practising purposes, I want to set the email body through email script, thus I created an Email Script and called it in this Notification (what it will contain) as shown in the above screenshot.
The Email Body Should be:
For the above Email Body I tried the below Email Script but not working as it's not displaying any content (Checked through 'Preview Notification' button).
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Get Variables
var reqFor = current.variables.requested_for.getDisplayValue(); //Variable 'requested_for' is Reference
var prop = current.variables.properties_this_change_affect.getDisplayValue(); //Variable 'properties_this_change_affect' is Reference
var effDt = current.variables.effective_date; //variable 'effective_date' is Date type
template.print('Hi,');
template.print("<br>"); //To Line Break
template.print('There is a new Workiva change for SAP Real Estate. Please find the details below:');
template.print("<br>"); //To Line Break
template.print('User: ');
template.print(reqFor);
template.print("<br>"); //To Line Break
template.print('Location: ');
template.print(prop);
template.print("<br>"); //To Line Break
template.print('Effective Date: ');
template.print(effDt);
template.print("<br>"); //To Line Break
template.print('Thank you,');
template.print("<br>"); //To Line Break
template.print('Service Desk');
})(current, template, email, email_action, event);
Requesting help on
1st- I checked the Email logs and did not find any notification email triggered, this means the notification is not triggered, seems I wrote the wrong advanced condition script or something, please help with advanced script condition so that It will get triggered (PS: through normal Condition filter I can dot walk like 'show related fields>variables>-------' but I want this to be achieved through Advanced Condition Script to access the Check box variable of this catalog item)
2nd- The Email body is not displaying content as set through Email Script, all the Variable Name is Correct, but still not displaying any content. (PS: This can be directly applied on Notification Body, but for practising I want this to be displayed through Email Script)
Thanks in Advance, need help for self-learning purposes.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2023 09:31 AM - edited 07-08-2023 09:32 AM
Hi @rishabh31 ,
In future try to ask those as separate questions not as a single question then it will be easy to understand and others will refer aswell.
1. for advance condition try below code
var grRITM = new GlideRecord("sc_req_item");
grRITM.addQuery('sys_id',current.sys_id);//to get the current RITM
grRITM.addQuery("cat_item", "cbd3f97b97e4111097af9300f153af71");//catlog item sysid
grRITM.query();
if (grRITM.next()){
var sapVal = grRITM.variables.u_sap_real_estate;//give your variable name
if (sapVal){
answer = true;
}
}
2. To call email script in notification use below
${mail_script:name_of_your_mail_script}
you given email instead of mail
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2023 12:23 AM
Hello Sir,
Just to revise the script to be more performance-optimized and when there is more than 1 such check box. Then the script would be:
var grRITM = new GlideRecord("sc_req_item");
grRITM.addQuery('sys_id',current.sys_id);//to get the current RITM
grRITM.addQuery("cat_item", "cbd3f97b97e4111097af9300f153af71");//catlog item sysid
grRITM.query();
if (grRITM.next()){
var sapVal = grRITM.variables.u_sap_real_estate;//give your variable name
if (sapVal == "true"){ //Pass 'true' here
answer = true;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2023 09:31 AM - edited 07-08-2023 09:32 AM
Hi @rishabh31 ,
In future try to ask those as separate questions not as a single question then it will be easy to understand and others will refer aswell.
1. for advance condition try below code
var grRITM = new GlideRecord("sc_req_item");
grRITM.addQuery('sys_id',current.sys_id);//to get the current RITM
grRITM.addQuery("cat_item", "cbd3f97b97e4111097af9300f153af71");//catlog item sysid
grRITM.query();
if (grRITM.next()){
var sapVal = grRITM.variables.u_sap_real_estate;//give your variable name
if (sapVal){
answer = true;
}
}
2. To call email script in notification use below
${mail_script:name_of_your_mail_script}
you given email instead of mail
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2023 10:56 AM
Thank you @Pavankumar_1 Sir, This is working fine🙂. Solution Marked Helpful and Accepted as Solution.
Sure, will ask separate questions for such asks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2023 12:23 AM
Hello Sir,
Just to revise the script to be more performance-optimized and when there is more than 1 such check box. Then the script would be:
var grRITM = new GlideRecord("sc_req_item");
grRITM.addQuery('sys_id',current.sys_id);//to get the current RITM
grRITM.addQuery("cat_item", "cbd3f97b97e4111097af9300f153af71");//catlog item sysid
grRITM.query();
if (grRITM.next()){
var sapVal = grRITM.variables.u_sap_real_estate;//give your variable name
if (sapVal == "true"){ //Pass 'true' here
answer = true;
}
}