- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 08:02 AM - edited 05-22-2023 08:09 AM
Hi All,
Below 2 blocks will be executed in a scheduled job and trigger the events, now in both blocks we have a set of different conditions and calling the events and both the block's event name is the same as below. now after this, we have a notification triggering based on the event fired and will send a notification via email script.
Now in the below notification email script how we can differentiate whether the event is triggered from which block of code i.e. //1st block or from //2nd block how this can be verified?
scheduled job.
//1st block
if (count2 > limit2)
gs.eventQueue('bpo.emailinjection.eml', gr, count, count2);
else {
gs.log("elseevent1");
gs.eventQueue('bpo.emailinjection', gr, count, count2);
}
//2nd block
if (count2 > limit2)
gs.eventQueue('bpo.emailinjection.eml', gr, count, count2);
else {
gs.log("elseevent2");
gs.eventQueue('bpo.emailinjection', gr, count, count2);
}
Notification email script.//sample
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 08:10 AM
send something unique from each block in event parameter and then use email script to check that
Something like this
//1st block
if (count2 > limit2)
gs.eventQueue('bpo.emailinjection.eml', gr, count, count2 + '@block1');
else {
gs.log("elseevent1");
gs.eventQueue('bpo.emailinjection', gr, count, count2);
}
//2nd block
if (count2 > limit2)
gs.eventQueue('bpo.emailinjection.eml', gr, count, count2 + '@block2');
else {
gs.log("elseevent2");
gs.eventQueue('bpo.emailinjection', gr, count, count2);
}
Email script
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var blockName = event.parm2.toString().split('@');
if(blockName == 'block1'){
// do something
}
else if(blockName == 'block2'){
// do something
}
var instancename1 = gs.getProperty("instance_name");
var ritm = parseInt(event.parm1);
gs.log("ritm"+ritm);
var attach = parseInt(event.parm2);
gs.log("attach"+attach);
//Property name updated
var limit = gs.getProperty('css_emailticket_threshold');
gs.log("limit"+limit);
var limit2 = gs.getProperty('css_emailticket_emlthreshold');
gs.log("limit2"+limit2);
email.setSubject("ALERT!! " + "\"" + instancename1 + "\"" + " instance - " + "Email ingestion monitoring");
attach = parseInt(attach);
gs.log("attach2"+attach);
limit2 = parseInt(limit2);
gs.log("limitsec"+limit2);
//RITM count and .eml count messages updated_07202022
if ((ritm < limit)) {
gs.log("1if");
if(attach > limit2){
gs.log("2if");
template.print("Please review Email ingestion and Email Client records without .eml file on " + "\"" + instancename1 + "\"" + " instance. Please check and take relevant actions as appropriate.");
template.print("<br /> <br />");
//RITM count messages updated_09222022
template.print("Total RITMs created or updated in last 1 hour: " + ritm + " (Threshold limit per hour - " + limit + ")");
template.print("<br /> <br />");
template.print("Total Email Client records without .eml file in last 1 hour (refer attachment): " + attach);
}
}
})(current, template, email, email_action, event);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 08:10 AM
send something unique from each block in event parameter and then use email script to check that
Something like this
//1st block
if (count2 > limit2)
gs.eventQueue('bpo.emailinjection.eml', gr, count, count2 + '@block1');
else {
gs.log("elseevent1");
gs.eventQueue('bpo.emailinjection', gr, count, count2);
}
//2nd block
if (count2 > limit2)
gs.eventQueue('bpo.emailinjection.eml', gr, count, count2 + '@block2');
else {
gs.log("elseevent2");
gs.eventQueue('bpo.emailinjection', gr, count, count2);
}
Email script
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var blockName = event.parm2.toString().split('@');
if(blockName == 'block1'){
// do something
}
else if(blockName == 'block2'){
// do something
}
var instancename1 = gs.getProperty("instance_name");
var ritm = parseInt(event.parm1);
gs.log("ritm"+ritm);
var attach = parseInt(event.parm2);
gs.log("attach"+attach);
//Property name updated
var limit = gs.getProperty('css_emailticket_threshold');
gs.log("limit"+limit);
var limit2 = gs.getProperty('css_emailticket_emlthreshold');
gs.log("limit2"+limit2);
email.setSubject("ALERT!! " + "\"" + instancename1 + "\"" + " instance - " + "Email ingestion monitoring");
attach = parseInt(attach);
gs.log("attach2"+attach);
limit2 = parseInt(limit2);
gs.log("limitsec"+limit2);
//RITM count and .eml count messages updated_07202022
if ((ritm < limit)) {
gs.log("1if");
if(attach > limit2){
gs.log("2if");
template.print("Please review Email ingestion and Email Client records without .eml file on " + "\"" + instancename1 + "\"" + " instance. Please check and take relevant actions as appropriate.");
template.print("<br /> <br />");
//RITM count messages updated_09222022
template.print("Total RITMs created or updated in last 1 hour: " + ritm + " (Threshold limit per hour - " + limit + ")");
template.print("<br /> <br />");
template.print("Total Email Client records without .eml file in last 1 hour (refer attachment): " + attach);
}
}
})(current, template, email, email_action, event);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 11:33 PM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 01:07 AM
its working thankyou. One more thing i need to add the instance name and the count in what it will contain option how this can be set? instance name should be dynamic?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 01:50 AM
you can use email script to get the instance name and also the count
Please mark my response as correct and close the thread.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader