Regarding creation of notification when catalog task is not being closed after 1 week

Shreya3
Tera Contributor

how we can built from scratch the code for creating notification to be sent to technology Ci Owner manager and cc technology ci owner and suppport group if catalog task has not yet been closed after 1 week. And also need help for creating notification to be sent to technology Ci Owner manager and cc technology ci owner and suppport group to create p1 incident and then send email if catalog task has not yet been closed after 2 weeks . please help on this. I have created  2 event registry  , 2 email notification and 1schedule job. but in schedule job i am not able to put proper code for both of the scenarios can anybody help on this asap, as I am new to this.

26 REPLIES 26

Hi @Shreya3 

 

Please find other message posted by me where I have shared the Scheduled Job script as well as the screenshot that I even tried on my Personal Developer Instance before showcase to you. Now, I can assure you it'll help you to get your query resolved. Let me know if you will be able to find it.

 

Thanks 🙂

Aakash Garg

ServiceNow Developer

gr_7days.addEncodedQuery('sys_created_onRELATIVELT@dayofweek@ago@7^sys_created_onRELATIVEGT@dayofweek@ago@8^state=1');
Akash i tried this filter in my instance but i am not able to fetch it . can you provide me screenshot for this filter from your PDI please. Sorry for asking so many things. Hope you understand.

Hi @Shreya3,

 

I already posted it. Hope you will be able to find it and please don't forget to mark my solutions and replies as helpful and accepted. 

 

Thanks 🙂

Aakash Garg

ServiceNow Developer

Shreya3
Tera Contributor

can anyone provide me with schedule job code for this as i am trying to glide record catalog task table and i want exact  on 7th day it should send notification to manager and if it is exact 14 days then it should create p1 incident and send notification to manager please. iam not able to get proper code. i am stuck.

Hi @Shreya3

Hope you are doing well.

 

I tried to find the solution in the form that you exactly needed and tried to implement the same on my Personal Developer Instance and coming up with the solution along with the scripts and snapshots that will really gonna help you and other to get the solution with the help of your question asked in the community.

 

Solution Proposed

As a solution, you need to follow just 3 small steps to achieve the task or requirement: -

  1. Create only one Schedule Job that will continuously run on a daily basis and check for the open tasks which have passed 1 week and 2 week of time. This job will trigger the event and creation of an incident respectively.
  2. Create 2 Events in "Event Registry" Table for both the notifications.
  3. Create 2 Notifications based on the Events get triggered.

Schedule Job Script: -

 

var tasks_7days = [];
var gr_7days = new GlideRecord("sc_task");
// Check if passes 7 Days
gr_7days.addEncodedQuery('sys_created_onRELATIVELT@dayofweek@ago@7^sys_created_onRELATIVEGT@dayofweek@ago@8^state=1');
gr_7days.query();
while (gr_7days.next()) {
	tasks_7days.push(gr_7days.sys_id.toString());
}
// Check if passes 14 Days
var tasks_14days = [];
var tasks_numbers = '';
var gr_14days = new GlideRecord("sc_task");
gr_14days.addEncodedQuery('sys_created_onRELATIVELT@dayofweek@ago@14^sys_created_onRELATIVEGT@dayofweek@ago@15^state=1');
gr_14days.query();
while (gr_14days.next()){
	tasks_numbers += gr_14days.number + ', ';
	tasks_14days.push(gr_14days.sys_id.toString());
}
if (tasks_7days.length!=0){
	gs.eventQueue('tasks_past_7_days', gr_7days, tasks_7days);
}
if (tasks_14days.length!=0){
	var gr_inc = new GlideRecord('incident');
	gr_inc.initialize();
	gr_inc.priority = 1;
	gr_inc.short_description = tasks_numbers;
	gr_inc.insert();
	gs.eventQueue('tasks_past_14_days', gr_14days, tasks_14days);
}

 

 

If you find this answer/solution/suggestion as helpful to your question asked or meet with your requirement, you can mark this solution/answer/suggestion as helpful, and correct.

 

Thanks 🙂

Aakash Garg

ServiceNow Developer