Catlog Item Creation on Daily for every 5 mins using Scheduled Job

Rajesh Bandila
Tera Contributor

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.

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.')
RajeshBandila_0-1719250189771.png

 

 
Thanks in Advance!!
1 ACCEPTED SOLUTION

Hi @Rajesh Bandila 

 

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

 

View solution in original post

5 REPLIES 5

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Rajesh Bandila 

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.');

ca333.PNG

 

Thanks and Regards

Sai Venkatesh

 

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!!

Hi @Rajesh Bandila 

 

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

 

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