- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2022 02:47 AM
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2022 02:51 AM
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
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-30-2022 02:51 AM
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
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-31-2022 07:18 AM
Not sure can you advise?
I could use this script running on background, the RITM is generated
BUT when I tried to put this script to 'scheduled job' and execute now, the RITM not generate.
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2022 08:00 AM
Hi,
are you sure the scheduled job was picked up by the scheduler?
Regards
Ankur
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-31-2022 07:22 PM