Script Master - 13: How to automatically close requests that are in a specific status.

Script Master - 13: How to automatically close requests that are in a specific status.

This week's script master post is about using Custom schedules feature which was released in our latest version 9300. The Custom Schedules feature enables you to access any data in ServiceDesk Plus to perform customized actions(specified in a customized script file) periodically. Each custom schedule can be given Query Reports as arguments to the script file. This enables access to the required data in ServiceDesk Plus through queries. 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.

This post will help you to automatically close requests that are left in a specific request status over a specific period of time.

 

Let us assume a scenario where the technicians reply to requests and put it in a custom status called 'Waiting for User'. The rules of the business demand that these requests be closed once in three days. This is achieved by running a query report in ServiceDesk plus which will return the ids of such 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'.The script file is available here.


You will find more information on Custom Schedules and sample usage scenarios in the 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" FROM WorkOrder wo LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID WHERE  ((std.STATUSNAME = 'Waiting for User') AND ((wo.CREATEDTIME >= <from_thisweek>) AND (wo.CREATEDTIME <= <to_thisweek>)))  AND wo.ISPARENT='1'


This will give you a list of the requests that were created in this week and are in "Waiting for User" status.

 

2. Download and copy the script file in the ManageEngine/ServiceDesk/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. Go to Admin--> Custom Schedules and set the Custom Schedule as shown below.


3. Install Python on ServiceDesk Plus server and set it up as shown in the below video.


4. Open up the script and change the URL and the Technician Key as mentioned within the script file.

5. Go to Admin--> Custom Schedules and set the Custom Schedule as shown below.



So, now the script will run every three days at 9 AM and will execute the query report to find out all the requests that are created this week and have the status of Waiting for User and will close the request.


Note: You need to ensure that the mandatory fields for request closure are filled when your technician moves the request to 'waiting for User', else the request cannot be closed.


A quick tip, using Field and Form rules (On Field Change), you can setup a rule to mandate the fields that have to filled in prior to request closing so that when the technician tries to change the status to Waiting for User, he cannot change the status until the fields are filled in.

 

Trust you found this post useful. In case you've missed the previous posts, visit here. Read through them and post your feedback as comments on the respective posts. See you next week with another useful script.


                New to ADManager Plus?

                  New to ADSelfService Plus?