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 ADSelfService Plus?

                    • Related Articles

                    • Script to Auto close Request when the status is Resolved for a particular number of days

                      For version 11 and above: -> In version 11, we only have the option to set the request Auto-close for a max of 10 days -> The below script will help you to extend the auto-closure time Execution steps: 1. Go to Reports--> New Query Report and run the ...
                    • 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 ...
                    • 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 ...
                    • Update status using Python script in 11.0

                      Using a Python script via custom trigger, we can update the status invoking an API call. A short guide on setting up python is available here : https://pitstop.manageengine.com/portal/kb/articles/how-to-setup-python-on-the-server Find the attached ...
                    • 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, ...