- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 10:30 AM
Hi,
I have created the one catalog item and that catalog item need to submit the system automatically on daily for every 5 mins. I have written the below Scheduled job script and it's working as expected when i click on Execute Now UI action button and it's not ordering system automatically. Please let me know how to automate the every 5 mins?
Please refer the below Script for your reference.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2024 11:23 AM
You can replace the below script and you can try it and it is working in my pdi
var currentDateTime = new GlideDateTime();
var currentDayOfWeek = currentDateTime.getDayOfWeek();
currentDateTime.setTimeZone('CET');
var gdt = new GlideDateTime();
var dateTimeString = gdt.toString();
var timesection = dateTimeString.split(' '); // Split the date and time sections
if (timesection.length === 2) {
var timeSection = timesection[1]; //getting the time part
var timeParts = timeSection.split(':');
if (timeParts.length === 3) {
var hour = timeParts[0];
var minute = timeParts[1];
var second = timeParts[2];
}
}
// Check if it's Monday at 7:00 AM CET
if (currentDayOfWeek == 2 && hour == 7 && minute == 0) {
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var catalogItemSysId = '7198552237b1300054b6a3549dbe5dea'; // Replace with the actual sys_id of the "AZA" catalog item
var item = cart.addItem(catalogItemSysId, 1);
var rc = cart.placeOrder();
gs.info('Created AZA catalog item.');
} else {
gs.info('Not the right time to create AZA catalog item. Current time: ' + currentDateTime);
}
Please mark helpful and mark as solution if everything works.
Thanks and Regards
Sai venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 11:08 AM
I have tried the code it is working in my PDI. and attached is the code and image
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var catalogItemSysId = '7198552237b1300054b6a3549dbe5dea'; // Replace with the sys_id
var item = cart.addItem(catalogItemSysId, 1);
var rc = cart.placeOrder();
gs.info('Created AZA catalog item.');
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 10:52 PM
Thanks @SAI VENKATESH
Yes, It's working fine when I Run as Periodically. Could you please let me know how to run the same script on every Monday at 7 am CET?
Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2024 11:23 AM
You can replace the below script and you can try it and it is working in my pdi
var currentDateTime = new GlideDateTime();
var currentDayOfWeek = currentDateTime.getDayOfWeek();
currentDateTime.setTimeZone('CET');
var gdt = new GlideDateTime();
var dateTimeString = gdt.toString();
var timesection = dateTimeString.split(' '); // Split the date and time sections
if (timesection.length === 2) {
var timeSection = timesection[1]; //getting the time part
var timeParts = timeSection.split(':');
if (timeParts.length === 3) {
var hour = timeParts[0];
var minute = timeParts[1];
var second = timeParts[2];
}
}
// Check if it's Monday at 7:00 AM CET
if (currentDayOfWeek == 2 && hour == 7 && minute == 0) {
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var catalogItemSysId = '7198552237b1300054b6a3549dbe5dea'; // Replace with the actual sys_id of the "AZA" catalog item
var item = cart.addItem(catalogItemSysId, 1);
var rc = cart.placeOrder();
gs.info('Created AZA catalog item.');
} else {
gs.info('Not the right time to create AZA catalog item. Current time: ' + currentDateTime);
}
Please mark helpful and mark as solution if everything works.
Thanks and Regards
Sai venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2024 11:20 PM
Thanks @SAI VENKATESH,
Could you please let me know, What's the Run filed (Weekly, Periodically, OnDemand) option that i need to select for this Script? If you attach the screenshot that will be more helpful.
Thanks & Regards
Bandila Rajesh