- 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-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:01 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 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();
}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 04:04 AM
the above script working fine but now mail trigger to only working days instead of all days so pls use above script it will useful for us and pls make it fast due to little bit urgent today
- 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:19 AM
Only monday to friday trigger mail to manager, no weakened like saturday and sunday