SEND AN NOTIFICATION USING SCHEDULE JOB

DEXTER RG
Tera Contributor

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

1 ACCEPTED SOLUTION

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');
}

})();

View solution in original post

10 REPLIES 10

Kailash Bhange
Kilo Sage
Kilo Sage

Hi There,
I have Created Article to send Notification using Schedule Job, please take a moment to review and update feedback.

Notify using Scheduled JOBS in ServiceNow


https://community.servicenow.com/community?id=community_article&sys_id=1dd55f001b255010ada243f6fe4bcba8

If the article helps you, please mark it as Helpful, Bookmark it, subscribe it and your feedback would be much appreciated.


Thank You!
Regards,
Kailash