Have a Scheduled Job to Create a Request only run Monday thru Friday

terrieb
Tera Guru

I created a scheduled job to create a request that I only want to generate on Monday thru Friday.

Below is the script I put into the advanced tab on the scheduled job record:

 

function checkCondition() {

    var gdt = new GlideDateTime();

    var dayOfWeek = gdt.getDayOfWeekLocalTime();

    // Monday is 1, Sunday is 7

    if (dayOfWeek >= 1 && dayOfWeek <= 5) {

        return true; // Run the job

    } else {

        return false; // Don't run the job

    }

}

 

However, it is run every day, including Saturday and Sunday.

 

Have I missed a step?

 

The job is scheduled to run Daily on the US/Eastern time zone schedule

 

Thanks!

1 ACCEPTED SOLUTION

Did you select the option to have the Flow variable as a boolean True/False ?

flow-variable-types.png

View solution in original post

9 REPLIES 9

Found out there were 2 scheduled jobs, so I made the 2nd one inactive!  Testing that now and if that was the problem, then the script worked.

 

If that doesn't solve it, then I will do the Flow step instead.

 

Thank you very much!

I quick question on the Flow part:

 

I was able to create the flow variable, but when I go to the If part, even though I select it, I don't get the option of "is" to select "false"

 

terrieb_0-1749469223308.png

 

Options are: 

terrieb_1-1749469260977.png

 

Picked wrong one??  

Put in the script on the flow variables:

terrieb_2-1749469419916.png

 

Did you select the option to have the Flow variable as a boolean True/False ?

flow-variable-types.png

Nope that is what I did wrong!

 

Thanks - flow is set.  

snehareddym
Tera Expert

snehareddym_0-1749473455453.png

In a Scheduled Job, I’ve written a sample script to test weekday-based conditions. The logic works correctly for Monday, Thursday, and Friday when answer = true. However, the time zone is not functioning as expected. I’ve tried debugging it, but the issue still persists. Kindly check the behavior in your respective time zone as well.