auto move state to close and set to inactive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 07:41 AM
Hello all
if my Request Item has been in awaiting approval for 60 days, I would like to set the state to closed and make it as inactive
How can I acheve this, can I get guideance please
Also if possible can it be a system property so it is easy to modify without by anyone in a case they decide to change the length of days
If not, any solution will do
I am new to all this, please be gentle
🙂 thank you all
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2023 08:30 AM
Create a Scheduled Script Execution:
- Navigate to "System Scheduler" in ServiceNow.
- Create a new Scheduled Script Execution record.
- Configure the schedule for when you want this script to run. For example, you can set it to run daily.
Create a Script:
In the Scheduled Script Execution record, specify the script that will run when the scheduled job executes.
(function() {
var targetState = 'awaiting_approval';
var daysThreshold = 60;
var now = new GlideDateTime();var gr = new GlideQuery('sc_req_item');
gr.addQuery('request.requested_for.state', targetState);
gr.query();
while (gr.next()) {
var requestedDate = new GlideDateTime(gr.getValue('sys_created_on'));
var daysSinceCreation = now.subtract(requestedDate).getDayPart();
if (daysSinceCreation >= daysThreshold) {
gr.setValue('state', 'closed');
gr.setValue('active', false);
gr.update();
}
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 07:27 PM
HI
This is what I have thus far, please let me know if I am on the right part as I am very confused
Also, do I need to create a system property, If so can you help please
Thank you