Send notification using Schedule Job.

itsangeleye
Giga Contributor

How can we generate a notification for the manager of the 'Requested For' user when a Requested Item (RITM) for a specific catalog item has a start date between 5 to 6 days ago?

1 ACCEPTED SOLUTION

Rushi Savarkar
Kilo Sage

Hello @itsangeleye 

Please find below code and let me know if that works for you

Schedule job:

var gr = new GlideRecord('sc_req_item');
gr.addQuery('cat_item', '620c2fb4c39b5a1004c43132b40131d1'); // replace your catalog item sys_id
gr.addQuery("variables.effe2774c35f5a1004c43132b4013141", "<=", gs.daysAgo(5)); //replace your start date variable sys_id
gr.query();
gs.info(gr.getRowCount());
while (gr.next()) {
gs.eventQueue('send.notification.demo', gr, gr.variables.manager, ''); // Event should be created
}

Thank you!

If my response helped you, please accept the solution and mark it as helpful.
Thank You!

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@itsangeleye 

so what did you start with and where are you stuck?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @itsangeleye 

 

It’s better to use Flow Designer, which is low-code and no-code—more efficient and easier to maintain.

 

https://www.servicenow.com/community/developer-forum/send-email-2-months-before-due-date/m-p/1789333

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Badrinarayan
Tera Guru

Hi @itsangeleye  , 

gs.eventQueue() Method

The eventQueue() method is part of the GlideSystem server-side API. The eventQueue() method inserts an event in an event queue. The eventQueue() method is typically passed four parameters but can also take an optional 5th parameter:

  1. Event name. Enclose the event name in quotes.
  2. GlideRecord object, typically current but can be any GlideRecord object from the event's table.
  3. Any value that resolves to a string. This is known as parm1 (Parameter 1). Can be a string, variable that resolves to a string, or method that resolves to a string.
  4. Any value that resolves to a string. This is known as parm2 (Parameter 2). Can be a string, variable that resolves to a string, or method that resolves to a string.
  5. (Optional) Name of the queue to manage the event.

example:

gs.eventQueue('event.name', GlideRecord, parm1, parm2); // standard form

gs.eventQueue('x_58872_needit.overdueNeedItTask',current,current.number,gs.getUserName());

 

Use gs.eventQueue in the scheduled script to trigger the event. Then configure a notification to be sent when the event is triggered.

Thanks & Regards,
Badrinarayan

Rushi Savarkar
Kilo Sage

Hello @itsangeleye 

Please find below code and let me know if that works for you

Schedule job:

var gr = new GlideRecord('sc_req_item');
gr.addQuery('cat_item', '620c2fb4c39b5a1004c43132b40131d1'); // replace your catalog item sys_id
gr.addQuery("variables.effe2774c35f5a1004c43132b4013141", "<=", gs.daysAgo(5)); //replace your start date variable sys_id
gr.query();
gs.info(gr.getRowCount());
while (gr.next()) {
gs.eventQueue('send.notification.demo', gr, gr.variables.manager, ''); // Event should be created
}

Thank you!

If my response helped you, please accept the solution and mark it as helpful.
Thank You!