- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2019 10:03 AM
Notification Timesheet not submitted to employee
As an employee, if i have not submitted my timesheet for the previous week before Monday at 2pm AEST
I should receive a notification requesting me to do so.
THANKYOU
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2019 10:33 AM
Hi Dexter,
I don't see "user" defined anywhere, it looks like you're trying to use it as a GlideRecord, however it's just a field on the Time Sheet Exceptions table. If you want to call that field you need to use the syntax timecard.user, not just user. Does the Notification run on the sys_user or time_sheet_exception table?
It looks like you have it set up to run on the User table. I would rewrite it this way then. I don't recommend nesting GlideRecords, so we'll build an array of users and then loop through that array to trigger the events. Also I'm going to use an Immediately Invoked Function Expression, instead of defining the function and then calling it. That's just extra steps. Also, use getUniqueValue() function to get sys_id's whenever possible, as you can get some funky behavior otherwise. I always convert sys_id's to strings just out of superstition because of the things I've encountered over the years lol.
I wasn't able to test this of course, but I think this should be pointing you in the right direction. Happy to assist further if needed.
(function () {
var userArr = [];
var timecard = new GlideRecord('time_sheet_exception');
timecard.addQuery('state','Not_Submitted');
timecard.addQuery('week_starts_on<=javascript:gs.daysAgoStart(7)');
timecard.query();
while(timecard.next()){
userArr.push(timecard.user.toString());
}
var user = new GlideRecord('sys_user');
for(var u=0; u < userArr.length; u++){
user.get(userArr[u]);
gs.eventQueue('time_card.late_submit', user, user.getUniqueValue(), user.manager);
gs.log('users' + user.getUniqueValue(), 'timecard');
}
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2019 10:08 AM
If you are a developer then you should be able to create a scheduled job and a notification.
- Create a new event
- Create a new notification
- Set trigger notification by an event and select the event you created above
- Create a scheduled job and write your script to check if you have submitted your timesheet or not and run it every Monday.
- If you haven't submitted then trigger the event and that will trigger the notification.
Good luck!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2019 10:15 AM
You don't need to write code for achieving this functionality.
You can achieve this using script-less scheduled jobs.
Please refer below for more details
https://community.servicenow.com/community?id=community_blog&sys_id=ae9caee1dbd0dbc01dcaf3231f96193d
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2019 10:16 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2019 10:33 AM
Hi Dexter,
I don't see "user" defined anywhere, it looks like you're trying to use it as a GlideRecord, however it's just a field on the Time Sheet Exceptions table. If you want to call that field you need to use the syntax timecard.user, not just user. Does the Notification run on the sys_user or time_sheet_exception table?
It looks like you have it set up to run on the User table. I would rewrite it this way then. I don't recommend nesting GlideRecords, so we'll build an array of users and then loop through that array to trigger the events. Also I'm going to use an Immediately Invoked Function Expression, instead of defining the function and then calling it. That's just extra steps. Also, use getUniqueValue() function to get sys_id's whenever possible, as you can get some funky behavior otherwise. I always convert sys_id's to strings just out of superstition because of the things I've encountered over the years lol.
I wasn't able to test this of course, but I think this should be pointing you in the right direction. Happy to assist further if needed.
(function () {
var userArr = [];
var timecard = new GlideRecord('time_sheet_exception');
timecard.addQuery('state','Not_Submitted');
timecard.addQuery('week_starts_on<=javascript:gs.daysAgoStart(7)');
timecard.query();
while(timecard.next()){
userArr.push(timecard.user.toString());
}
var user = new GlideRecord('sys_user');
for(var u=0; u < userArr.length; u++){
user.get(userArr[u]);
gs.eventQueue('time_card.late_submit', user, user.getUniqueValue(), user.manager);
gs.log('users' + user.getUniqueValue(), 'timecard');
}
})();