Schedule job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
we will do the development and deployment of an automation in that identifies and closes IT requests that have remained in an “Awaiting Approval” state for more than 45 days without any activity.
Automation will be built as mentioned below.
-Detect IT requests that have had no updates from the requestor within the 45‑day period.
-Detect requests where the assigned approver has taken no approval action (approve or reject) during that timeframe.
-Automatically transition qualifying requests to a Closed – Inactive status.
-Add a standardized system‑generated comment at closure to inform users of the reason for the auto‑closure and the appropriate next steps.
Auto‑Closure Comment:
“This request is proposed to be automatically closed due to inactivity while awaiting approval. No updates or approval actions were recorded during this period. If access or support is still required, the requestor may submit a new request.”
can anyone suggest me easily way to do it I'm getting error in this request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @RoshaniB,
I would suggest you develop a scheduled job that will run once a day/week. I am gonna assume by requests you referring Requested Items (sc_req_item) give you my logic on the code below you can alter it to fit your ServiceNow instance where required
var gr = new GlideRecord('sc_req_item');
gr.addQuery('state', 'awaiting_approval');
gr.addQuery('sys_updated_on', '<=', gs.daysAgoStart(45));
gr.query();
while (gr.next()) {
var appr = new GlideRecord('sysapproval_approver');
appr.addQuery('sysapproval', gr.sys_id);
appr.addQuery('state', 'requested');
appr.query();
if (appr.hasNext()) {
gr.state = 'closed_inactive'; //substitute with you closed state value
gr.comments = 'This request is proposed to be automatically closed due to inactivity while awaiting approval. No updates or approval actions were recorded during this period. If access or support is still required, the requestor may submit a new request.';
gr.update();
}
}
