How to create scheduled job to auto generate RITM ticket every 2nd Tuesday of each month?

Bird1
Mega Sage

Hello

I have a requirement to create scheduled job to auto generate RITM ticket in every Tuesday of each month. I am not sure that it's possible? I tried to go to scheduled job but it could only select the date but unable to select 2nd Tuesday of month as I need.

 

find_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

yes it's possible

1) make schedule job run daily and check in condition field if it's 2nd Tuesday of month

How to get second tuesday of every month for scheduling the report in servicenow

2) then in script section you can use Cart API to submit the request and RITM and REQ will get generated

something like this

try{
	var cartId = GlideGuid.generate(null);
	var cart = new Cart(cartId);
	//add your requested item to the cart by sys_id of the catalog item
	var item = cart.addItem('0336c34407d0d010540bf2508c1ed096', 1);

	//fill in the variables on the request item form
	cart.setVariable(item, "asset", "00a96c0d3790200044e0bfc8bcbe5dc3");
	cart.setVariable(item, "multiple_choice", "Phoenix");
	var rc = cart.placeOrder();
	gs.info(rc.number);

}
catch(ex){
	gs.info(ex);
}

Regards
Ankur

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

yes it's possible

1) make schedule job run daily and check in condition field if it's 2nd Tuesday of month

How to get second tuesday of every month for scheduling the report in servicenow

2) then in script section you can use Cart API to submit the request and RITM and REQ will get generated

something like this

try{
	var cartId = GlideGuid.generate(null);
	var cart = new Cart(cartId);
	//add your requested item to the cart by sys_id of the catalog item
	var item = cart.addItem('0336c34407d0d010540bf2508c1ed096', 1);

	//fill in the variables on the request item form
	cart.setVariable(item, "asset", "00a96c0d3790200044e0bfc8bcbe5dc3");
	cart.setVariable(item, "multiple_choice", "Phoenix");
	var rc = cart.placeOrder();
	gs.info(rc.number);

}
catch(ex){
	gs.info(ex);
}

Regards
Ankur

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

Not sure can you advise?

 

I could use this script running on background, the RITM is generated

find_real_file.png

 

find_real_file.png

 

BUT when I tried to put this script to 'scheduled job' and execute now, the RITM not generate.

 

find_real_file.png

 

 

var dt = '2022-05-10 00:00:19';
var gdt = new GlideDateTime(dt);
gs.print(gdt);
var day = gdt.getDayOfWeek();
var days = gdt.getDayOfMonthLocalTime();
gs.print(day);
gs.print(days);

if (day == 2 && ((days > 7 && days <=14) || (days >21 && days <=28))) {
result = true;
} else {
result = false;
}
gs.print(result);

if (result == true) {
var cart = new sn_sc.CartJS();
var request =
{
'sysparm_id': 'b314ca820f510300dfdbb97ce1050e48',
'sysparm_quantity': '1',
'variables':{
'summary': 'Please install updates on UCC servers',
'details': 'This is scheduled job every 2nd Tuesday of each month to remind you to install updates on UCC servers',
'requested_for': 'd6185da7db1a5f8063f7d5ab5e961955',


}
};
var cartDetails = cart.orderNow(request);
gs.info(cartDetails);
}

Hi,

are you sure the scheduled job was picked up by the scheduler?

Regards
Ankur

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

Hi Ankur,

 

Sorry I found I chose the wrong type of scheduled job. I chose 'Scheduled Entity Generation'. After I changed to 'Scheduled Script Execution', it's workable. 

find_real_file.png

thanks.