Script to auto close requests based on last updated time and status (Python)

Script to auto close requests based on last updated time and status (Python)

This post describes the use of a python script to close requests based on the last updated time and requests set in Resolved status using Custom Schedules. 

What is 'Custom Schedules' ?

The Custom Schedules feature enables you to access any data in ServiceDesk Plus to perform customized actions  periodically. Each custom schedule can associate Query Reports as arguments to a script file.  You can even synchronize ServiceDesk Plus data with other third-party applications to perform various actions, such as send mailer campaigns to requesters at regular intervals or update various attributes of requests periodically.You will find more information about this feature in document available here.      



Execution steps:

1. Go to Reports--> New Query Report and run the below query and save this report.

SELECT wo.WORKORDERID AS "Request ID", wo.TITLE AS "Subject", std.STATUSNAME AS "Request Status", wos.LAST_TECH_UPDATE AS "Last Update Time", ad.ORG_NAME AS "Account" FROM WorkOrder wo LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID LEFT JOIN AccountSiteMapping asm ON wo.SITEID=asm.SITEID LEFT JOIN AccountDefinition ad ON asm.ACCOUNTID=ad.ORG_ID 

WHERE  std.STATUSNAME like '%Resolved%' and extract(epoch from(now()::TIMESTAMP -  to_timestamp(wos.LAST_TECH_UPDATE/1000)::TIMESTAMP))/3600/24 < 7
order by wos.workorderid limit 500;

This will give you the ID of requests under Resolved status and the last updated is before 7 days. You shall change the last updated number of days as per your requirement. Running the report under Reports - > New query report will show the requests matching the report criteria. Save the Report as Resolved Requests. 


2. Download the script file and the function.py and place them in the location ManageEngine/ ServiceDeskPlus-MSP/ integration/custom_scripts folder.

(Note: Don't replace functions.py and configuration.json files if they already exist in that location)

3. Update the technician key and the application URL in the configuration.json file attached. The technician API key can be generated by clicking on the technician Profile icon in top right - > Generate API Key

4. Configure the schedule under Admin--> Custom Schedule



A short guide on setting up python is available here.



                  New to ADManager Plus?

                    New to ADSelfService Plus?

                      • Related Articles

                      • Script to Auto close Request when the status is set to Resolved

                        This post describes the use of a python script to close requests that are set in Resolved status using Custom Schedules What is 'Custom Schedules' ? The Custom Schedules feature enables you to access any data in ServiceDesk Plus to perform customized ...
                      • Close the request upon adding a note.

                        Kindly follow the steps mentioned below: 1) Go to Admin >> Developer Space >> Custom Function >> Global Functions >> Copy & Paste the attached GF_Content.txt and save it with a name. Update the URL and technician key as per your instance. Refer to ...
                      • Script to bulk close change using deluge script based on the status

                        The following script will help you bulk close changes based on the status of change using custom schedules 1. Go to Reports tab --> New query report --> copy the query to the query editor and run the report. Save the report in the folder. The query ...
                      • Python script to update request status

                        This article consists of a python script to update the request status based on a criteria set in Custom trigger. For installation and setup of PYTHON, please refer the below link, ...
                      • How to automatically close requests that are in a specific status.

                        This post describes the use of a python script to close requests that are put in a specific status using Custom Schedules.This showcases the use of a feature called 'Custom Schedules' that was released in the build 9300 of ServiceDesk Plus. What is ...