- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2020 07:35 AM
HI All,
I have a requirement that if a task assignment group is XYZ and if Assigned to is NOT empty, I need to close the task marked "Closed Complete" within 3 Business Days (Monday to Friday between 9AM and 5PM) . Please guide
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 01:50 PM
If this has solved your problem, kindly mark the comment as a correct answer so that the question is moved to the solved list.
Regards,
Asif
2020 ServiceNow Community MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2020 08:11 AM
Create schedule job from it to automatically close any catalog task (sc_task) that has been set to a status of Resolve for greater than 3 days.
autoCloseSc_task();
function autoCloseSc_task() {
var ps = gs.getProperty('glide.ui.autoclose.time');
var pn = parseInt(ps);
if (pn > 0) {
var gr = new GlideRecord('sc_task');
gr.addQuery('state', '10');
gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(pn));
gr.query();
while (gr.next()) {
gr.state = '3';
gr.work_notes = 'Task automatically closed after ' + pn + ' days in the Resolved state.';
gr.active = false;
gr.update();
}
}
}
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2020 08:29 AM
As it is based on a condition, I have to do it with Business rule I believe

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2020 08:58 AM
you can use same code in business rule as well.
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2020 08:34 AM
Hi Gagandeep,
You can create a scheduled job as below considering you have a Schedule that runs Mon-Friday 9-5 just copy the sys_id of schedule & replace it below
gs.include('DurationCalculator');
var gdt = new GlideDateTime();
var target = new GlideRecord('yourtablename'); //Replace table here
target.addQuery('assigned_to', ''); //Checks if assigned_to is empty
target.addQuery('assignment_group.name','XYZ'); //Replace name here correctly
target.query();
while (target.next()) {
var dc = new DurationCalculator();
dc.setSchedule('e40528d51bdfe7008009eb186e4bcbf8'); //pass sys_id of schedule that is Mon-Fri 9-5
var secdf = dc.calcScheduleDuration(target.sys_created_on.getDisplayValue(), gs.nowDateTime());
if (secdf > 60 && secdf < 161999) { // Greater than 3 Days.
if (target.state != 3) //3 is close but the state is not closed so close it below
{
target.state = 3; //close it & update
target.update();
}
}
}
Only issue I find it you will have to make it run twice or once per day so as to make tickets change state to close accordingly. Similar was the case where I did use workflow but & timer activities but above as well should work.