Condition Script

yoli1
Tera Contributor

Hi team, is there a possibility to add a custom field to the scheduled jobs form, allowing the user to choose how many months until the scheduled job is triggered again? For example, if they want it to run on a quarterly basis, they can simply select '3 months' instead of using a Condition Script

14 REPLIES 14

Bert_c1
Kilo Patron

Hi yoli1,

 

You can use Run: "Periodically" and Repeat Interval: Days: "90"

 

Screenshot 2023-09-02 153850.png

Or you can choose 'Business Calendar' and select the OOB "Quarter". And define the desired entries for that Business Calendar.

yoli1
Tera Contributor

Hi @Bert_c1 Thanks, but choosing 60 days isn't always right as we don't have 30 days every mouth we might have 31 days in a month. and thank for your suggestion about using the Business Calendar. but with Business Calendar = Quarter what should the Run field be set at ? Screen Shot 2023-09-03 at 2.21.41 PM.png

varaprasad123
Kilo Guru

I think you can create a custom field on scheduled job to determine the next custom schedule run, if you are absolutely didn't find a solution with what we have in OOB. Along with the custom new field  following script would help to calculate next action date.

 

// Assuming you have a custom field "months_until_next_run" on the Scheduled Job form
var monthsUntilNextRun = current.months_until_next_run;

if (isNaN(monthsUntilNextRun) || monthsUntilNextRun <= 0) {
    // Handle invalid input
    gs.addErrorMessage('Please enter a valid number of months.');
    current.setAbortAction(true);
} else {
    // Calculate the next run date
    var currentDate = new GlideDate();
    currentDate.addMonths(monthsUntilNextRun);
    
    // Update the "Next Action" field with the calculated date
    current.next_action = currentDate;
}

Rajesh_Bhise
Tera Guru

Hello @varaprasad123 ,

 

Yes you can create custom field on scheduled job table and use it for date. 

But to you need to override the OOTB includes that trigger the execution of the scheduled job (field - starting).

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Thank You,

Rajesh