Email Notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
I have setup an email notification in ServiceNow that is intended to send a message to the end user specific end user and a the person selected in a variable field called
I ran a few tests and checked the email logs, but unfortunately, no emails were sent to end user or the user identified in the preceptor field.
I've attached screenshots of my configuration for your review.
Script being used via Scheduled Jobs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @Swebb ,
Make sure you are only sending two parameters ( I see you are having 3 with null). eventQueue() only supports two parameters for substitution
gs.eventQueue(
'custom.notify.manager.nonemployee',
gr,
gr.request.requested_for.toString(), // end user
gr.variables.preceptor.toString() // preceptor
);
Mark this as helpful and correct if this helps you.
Thanks,
Yaswanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
@Swebb, your "IF Condition" is failing... See snip below. (endDateStr === targetDateStr) is returning false. Replace (Strict Equality Operator ===) with (Equality Operator ==) and see if that works???
One side note though, I would suggest to use Flow Designer. You have low code approach for this and you wouldn't need to create events and all this extra configuration. Everything will come in one place handy. Easy to debug and in future if any one wants to modify, debug or make any sort of changes would be easier. (I leave the choice to you.)
Note : As a best practice always have a condition before running any while loop in the scheduled job. If anything goes wrong in your script it will hamper the performance of the system. Have a "try - catch" method and "else" condition whenever using "if" to find out what's running and catch the error. This is to stop any unwanted operation that could run endlessly in unsupervised script execution.
Remember - "Running freeform script can cause system disruption or loss of data."
Hope this helps.
Let me know if it worked.
Regards,
Vikas K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
Hi @Swebb
In your script you’re calling:
var endDate = new GlideDateTime(gr.variables.end_date);
Problem: variables is only available in Catalog Client Scripts / Flow / Server-side processing but not directly accessible in a GlideRecord like that.
For catalog items, the RITM (sc_req_item) stores answers in sc_item_option and sc_item_option_mtom tables.
You can’t do gr.variables.end_date directly in a Scheduled Job script.
Fix: Use new GlideappVariablePoolQuestionSet() API or query sc_item_option table to pull the variable value.
Code exemple:
var itemVars = new GlideappVariablePoolQuestionSet();
itemVars.setRequestID(gr.sys_id);
itemVars.load();
var endDateVar = itemVars.getQuestion('end_date'); // replace with the variable name
var endDate = new GlideDateTime(endDateVar.getValue());
Same issue in gr.preceptor doesn’t exist as a field on sc_req_item.
If preceptor is a variable, you need to retrieve it with the same method as above.
instead of:
var preceptorVar = itemVars.getQuestion('preceptor');
var preceptorSysId = preceptorVar.getValue();
Use:
gs.eventQueue(
'custom.notify.manager.nonemployee',
gr,
preceptorSysId,
null,
null
);