Adding condition to a scheduled job

Pratiksha Lang1
Kilo Sage

Run scheduled job script on last day of each month for monthly frequency. if frequency is quarterly then it should run on last day of quarter. if frequency is yearly then it should run on last day of year. if frequency is half yearly then it should run on last day of half year. 

3 REPLIES 3

Ratnakar7
Mega Sage
Mega Sage

Hi @Pratiksha Lang1 ,

 

You can configure the conditions based on the frequency of the job. Here's an example:

  • If the frequency is "monthly," add a condition that checks whether the current day is the last day of the month. The condition would look like this: gs.isLastDayOfMonth().
  • If the frequency is "quarterly," add a condition that checks whether the current day is the last day of the quarter. The condition would look like this: quartersAgoEnd(Number quarters) - Returns the date and time for the last day of the quarter for a specified number of quarters ago.
  • If the frequency is "yearly," add a condition that checks whether the current day is the last day of the year. The condition would look like this: gs.isLastDayOfYear().

 

If my response helps you to resolve the issue close the question by Accepting solution and hit 👍thumb icon. From Correct answers others will get benefited in future.

 

Thanks,

Ratnakar

Ankur Bawiskar
Tera Patron
Tera Patron

@Pratiksha Lang1 

so are you having only 1 scheduled job? if yes then what's the configuration etc

share screenshots.

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

@Ankur Bawiskar Yes there is only 1 scheduled job in which I have written the script which I want to execute on the basis of frequency field value. for example. for monthly frequency it should run on every month last day and for quarterly on last day of quarter. 

PratikshaLang1_0-1679389807594.png

 

In this condition I have to write it to run the scheduled job on monthly, quarterly etc