JavaScript Query for Previous Week

rdskn023ET
Tera Contributor

Hi,

 

This may be a basic question, but for some reason I am struggling with it. We have a script that will generate our time sheets every Sunday at noon. In ServiceNow, the week starts on begins on Monday. What I am looking to do is have a notification sent out to users who have not submitted their time sheets for the previous week as of Monday at noon. I can't seem to figure out the query for previous week since time sheets use Sunday as the first day of the week and the system uses Monday. If I use the query in my code for last week, it still pulls the data for the current week. So on Monday, how do I pull the time sheet data created from the previous week to see who has not submitted time. For instance, if the 1st of the month is a Sunday and that is when the time sheet is created, come Monday the 9th, I want to pull the time sheets from the 1st and display who is still pending. Obviously, I need this for every Monday, so I can't simply plug dates in. Any help would be greatly appreciated. 

 

Thanks!!

1 ACCEPTED SOLUTION

Nia McCash
Mega Sage
Mega Sage

If Time Sheets always start on Sundays and you are always running the check on Mondays, it may suffice to check for dates that are between 9 days ago and 1 day ago:

NiaMcCash_0-1679412835676.png

 

Try it in the list GUI and confirm that you're getting the expected results.

If you need the query for a script, you can right-click on the filter and get an encoded query that you can use as part of a script:

NiaMcCash_1-1679412904097.png

 

 

 

View solution in original post

2 REPLIES 2

Nia McCash
Mega Sage
Mega Sage

If Time Sheets always start on Sundays and you are always running the check on Mondays, it may suffice to check for dates that are between 9 days ago and 1 day ago:

NiaMcCash_0-1679412835676.png

 

Try it in the list GUI and confirm that you're getting the expected results.

If you need the query for a script, you can right-click on the filter and get an encoded query that you can use as part of a script:

NiaMcCash_1-1679412904097.png

 

 

 

Thanks Nia!