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?

        Resources

            • 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 ...
            • 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 ...
            • Query to show last updated field.

              Kindly go to Reports-New Query Report and execute the below query.  PGSQL: SELECT wo.WORKORDERID AS "Request ID",  max(wo.TITLE) AS "Subject",  max(ti.FIRST_NAME) AS "Assigned Technician",  max(aau.FIRST_NAME) AS "Requester",  ...
            • Python script to automate FCR

              Please find the attached Python script on this link  to automate FCR via custom trigger when the request is created and resolved by the same technician. The link contains two Python scripts with the name FCR.py (this script can be used when MSP is ...