- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2025 04:57 AM
var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('active=true^cat_item=uvsdalvyut6768s8^approval=requested^sys_created_onRELATIVELT@dayofweek@ago@3');
gr.query();
while (gr.next()) {
var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('active=true^cat_item=uvsdalvyut6768s8^approval=requested^sys_created_onRELATIVELT@dayofweek@ago@3');
gr.query();
while (gr.next()) {
var createdDate = gr.getValue('sys_created_on');
var createdGlideDate = new GlideDateTime(gr.sys_created_on).getLocalDate();
var getExpDate = createdGlideDate.getDate();
var curDateTime = new GlideDateTime();
var curDate = curDateTime.getLocalDate();
var forEmailsgetDays = GlideDateTime.subtract(getExpDate, curDate);
var reminderDays = forEmailsgetDays.getDayPart();
if (reminderDays > 3 && reminderDays <= 5) {
// Escalate to line manager's manager
var lineManager = gr.variables.user_id.manager;
var managerGR = new GlideRecord('sys_user');
if (managerGR.get(lineManager)) {
var managerManager = managerGR.manager;
if (!managerGR.manager.vip) {
gs.eventQueue('kf_inactive_line_manager', gr, lineManager, managerManager);
}
}
}
else if (reminderDays > 5) {
// Reject the request
gr.state = -35;
gr.stage = 'Closed Rejected';
gr.approval = 'rejected';
gr.active = 'false';
gr.comments = "Request rejected due to lack of approval within 5 days";
gr.setWorkflow(false);
gr.update();
}
Please provide additional script like it will trigger email to manager only working days irrespective all days
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2025 05:11 AM - edited 07-15-2025 05:16 AM
Hi @Nareshpatel,
Your script has issues with subtraction. You can try this updated script.
var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('active=true^cat_item=uvsdalvyut6768s8^approval=requested^sys_created_onRELATIVELT@dayofweek@ago@3');
gr.query();
while (gr.next()) {
var createdGDT = gr.getValue('sys_created_on');
var created = new GlideDateTime(createdGDT);
var now = new GlideDateTime();
var diff = GlideDateTime.subtract(now, created);
var diffDays = Math.floor(diff.getNumericValue() / (1000 * 60 * 60 * 24));
if (diffDays > 3 && diffDays <= 5) {
// Escalate to line manager's manager
var lineManager = gr.variables.user_id.manager;
var managerGR = new GlideRecord('sys_user');
if (managerGR.get(lineManager)) {
var managerManager = managerGR.manager;
if (managerManager && !managerManager.vip) {
gs.eventQueue('kf_inactive_line_manager', gr, lineManager, managerManager);
}
}
}
else if (diffDays > 5) {
// Reject the request
gr.state = -35;
gr.stage = 'Closed Rejected';
gr.approval = 'rejected';
gr.active = 'false';
gr.comments = "Request rejected due to lack of approval within 5 days";
gr.setWorkflow(false);
gr.update();
}
}
Regards,
Ehab Pilloor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2025 05:15 AM
Hello @Nareshpatel ,
Please use code below so it will trigger email to manager only working days irrespective all days -
// Define your business calendar sys_id.
// IMPORTANT: Replace 'YOUR_BUSINESS_CALENDAR_SYS_ID' with the actual Sys ID
// of your organization's working days calendar (e.g., '8-5 weekdays').
// You can find this in System Scheduler > Schedules > Schedules.
var businessCalendarSysId = 'YOUR_BUSINESS_CALENDAR_SYS_ID';
var schedule = new GlideSchedule(businessCalendarSysId);
var currentTime = new GlideDateTime(); // Get the current date and time
// Check if the current time falls within the defined schedule (working hours and days)
if (schedule.isInSchedule(currentTime)) {
// Only send email if it's a working day AND not a VIP manager
if (!managerGR.manager.vip) {
gs.eventQueue('kf_inactive_line_manager', gr, lineManager, managerManager);
gs.log('Email sent for RITM: ' + gr.number + ' to line manager\'s manager. Reminder days: ' + reminderDays);
} else {
gs.log('Email not sent for RITM: ' + gr.number + '. Manager is VIP.');
}
} else {
gs.log('Email not sent for RITM: ' + gr.number + '. Today (' + currentTime.getDisplayValueInternal() + ') is not a working day based on calendar: ' + businessCalendarSysId);
}
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2025 05:16 AM
what's your actual business requirement?
what did you configure and where have you written the above script?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 02:00 AM
Can you provide latest script ?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 04:10 AM
I want to confirm the requirement again, so you want to send the notification for all days?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 04:30 AM
Yes, I am checking
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2025 06:34 AM
Hi i pasted script is working fine but the thing it should trigger the mail to managers when its working days not entire week, could you please provide update script use glide schedule so, pls use my script instead of this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2025 05:16 AM
what's your actual business requirement?
what did you configure and where have you written the above script?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2025 06:32 AM
i pasted script is working fine but the thing it should trigger the mail to managers when its working days not entire week, could you please provide update script use glide schedule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 01:56 AM
Hi i pasted script is working fine but the thing it should trigger the mail to managers when its working days not entire week, could you please provide update script use glide schedule so, pls use my script instead of thi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 01:56 AM
use glide schedule api