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

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 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.

Use Case:

Let us assume a scenario where the technicians resolves a request and places the request on Resolved status. As per requirement to close resolved requests after an hour  (Schedule can be customized based on requirement Days/ hours ) . This is achieved by running a query report under Servicedeskplus-msp which will return the  ids of Resolved requests. These are provided as input to a python script in json format.The script then uses request API to update those request's status as 'closed'.

Execution steps:

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

SELECT wo.WORKORDERID AS "Request ID",ad.ORG_NAME AS "Account" FROM WorkOrder wo LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID INNER JOIN Accountsitemapping asm ON wo.siteid=asm.siteid INNER JOIN AccountDefinition ad ON asm.accountid=ad.org_id LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID LEFT JOIN WorkOrderHistory woh ON wo.WORKORDERID = woh.WORKORDERID LEFT JOIN WorkOrderHistoryDiff wohd ON woh.HISTORYID = wohd.HISTORYID LEFT JOIN StatusDefinition std1 ON cast(cast(wohd.prev_value AS varchar) AS int) =std1.STATUSID LEFT JOIN StatusDefinition std2 ON cast(cast(wohd.current_value AS varchar) AS int) = std2.STATUSID WHERE  ((( OPERATIONTIME >= <from_thisyear> ) AND ( OPERATIONTIME <= <to_thisyear> )))  AND wo.ISPARENT='1' and wohd.COLUMNNAME IN ('STATUSID')  and std.STATUSNAME = 'Resolved'  group by wo.WORKORDERID,ad.ORG_NAME

This will give you the ID of requests under Resolved status. Save the Report as Resolved Request

2. Downloaded and place the script file in the ManageEngine/ ServiceDeskPlus-MSP/ integration/custom_scripts folder.
3. Update the  application URL and the Technician Key  in the script with the help of the comments provided within.
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 ...
                    • Change Auto closure

                      This will be helpful in auto closing change request after X days it is in review stage. This use case is more suitable in environments where ONLY Requesters (customers) are the Change Reviewers and they want the Change to be closed if no review is ...
                    • 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 ...
                    • Send Auto reminders to Change Approvers after X days

                      Here is the script and kindly follow the steps below to achieve your requirement to send Auto reminders to Change Approvers after X days. For now, the script sends reminder for every 24 and 48 hours. This can be customized in the script. 1.Download ...
                    • 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 ...