Using Calculations to replace and enhance AutoClose (or automatically move any process on to any status with any action)

Version 11

    Verified Product Versions

    LANDESK Service Desk 7.6LANDESK Service Desk 7.7.xLANDESK Service Desk 2016.xLANDESK Asset Central 2016.x

    The AutoClose service has been available to automatically close incidents after they have been resolved for x hours.  This is a great tool however has its limitations.  It is only for incidents (not Call, Tasks, etc) and is limited to performing the Close action.  With the introduction of calculations and the existing scheduled bulk actions functionality we can now replace the AutoClose service and with it comes more flexibility.

     

    In this example we are going to use calculations to replicate the AutoClose behaviour and close incidents that have been resolved for over 7 days.  Service Desk version 7.3.1 or higher is required for all calculations functionality.

     

    Stage 1 - The Scheduled Calculation

    We need a calculation formula to check if the incident is ready to be closed.  This will get calculated every night (see stage 2) but first we need to create a checkbox which will store our calculation result:

     

    1. On the Incident object create a new attribute called "AutoClose Flag".

    2. Set the data type to Boolean and the Default Value to False.

    3. Set the Calculation Type to Scheduled.  This will pop up the Calculation Editor.

    4. Enter the following formula (commented here for readability):

     

    import System
    static def GetAttributeValue(Incident):
     // initially set the flag to False
     Flag = 'False'
     
     // check the incident is resolved
     if Incident.Status.Name == 'Resolved':
     
      // check if the latest resolution was over 7 days ago
      Resolution = Incident.Resolutions.Latest()
      TimeSinceResolved = Incident.GetBusinessTime(Resolution.CreationDate, DateTime.UtcNow)
      if TimeSinceResolved.TotalHours > 40:
     
       // if today isn't Saturday or Sunday enable the flag
       if DateTime.Today.DayOfWeek != DayOfWeek.Saturday and DateTime.Today.DayOfWeek != DayOfWeek.Sunday:
        Flag = 'True'
     
     // return the True or False flag 
     return Flag
    

     

    The GetBusinessTime() method is used to determine how long the incident has been resolved based on the calendar of the current SLA.  We then check to see if the total hours is greater than 40 (a five day week working 8 hours a day).   This can be changed to any value to suit but must be in hours.  You could also change which attribute being checked against rather than Resolution.CreationDate.  If you want to automatically move a process that is With Customer you could use the creation of the With Customer collection instead of the Resolution collection.  We're checking against DateTime.UtcNow which is the current time in the UTC timezone.  This is used rather than DateTime.Now (local time) as the Creation Date we're checking with is also in UTC as are most DateTime attributes.

     

    The status name is checked against and is checking for "Resolved".  This can be changed to suit and could be expanded to multiple statuses using an OR in the If statement such as: if Incident.Status.Name == 'Resolved' or Incident.Status.Name == 'WithCustomer':

     

    Stage 2 - Scheduling the calculation

    We've created a scheduled calculation, we now need to create a schedule for it.  The schedule needs a query of incidents to check against so also need to create this:

     

    1. In Query and Report Designer create a new system query.

    2. Call it "Resolved Incidents" and base it on the Incident object.

    3. Set the criteria to: Status Is Equal To ( Resolved ).

     

    With the query to check against we can now create the schedule:

     

    1. In Schedule Manager on the Bulk Action Management panel select New Scheduled Bulk Action.

    2. Name it "AutoClose Calculation Check" or similar.

    3. Set the schedule to run Daily at 20:30 (or anytime over night that is out of hours).

    4. Set the Module to Incident Management, object to Incident and Query to the "Resolved Incidents" we just created.

    5. Set the Scheduled Action Type to Perform Calculation.

    6. Press the Calculations button and on the dialog that appears move our AutoClose Flag attribute to the right-hand panel and press OK.

    7. Press the Save button to save the schedule.

     

    In this example we're setting the scheduled calculation to run every night at 8:30.  This can of course be changed as depending on the time frame you're using you may only want the incidents to get closed once a week, month etc...  The time of day is not important but is relevant to the third and final stage...

     

    Stage 3 - Schedule the Close action

    The scheduled calculation will set a tick a box on the incident for us but won't actually close it.  To do that we need another schedule to actually close the incidents.  As before we need to create a query for the schedule to run against:

     

    1. Copy the "Resolved Incidents" query and name it "Resolved Incidents due to be AutoClosed".

    2. Add a 2nd criteria of: AND AutoClose Flag Is Equal To ( True ).

     

    Finally we create the schedule:

     

    1. Create a new Scheduled Bulk Action as before.

    2. Name is "AutoClose Action".

    3. Set the schedule to run Daily as before but 30 minutes after the calculation schedule: 21:00.

    4. Set the Module to Incident Management, object to Incident and Query to the "Resolved Incidents due to be AutoClosed" we just created.

    5. Set the Scheduled Action Type to Run Action and choose Close as the action.

    6. Press the Window Data... button to bring up the Close window and fill out the fields as you'd like them to be filled out when the action is performed.

    7. Press the Save button to save the schedule.

     

    You can use this technique for any action, not necessarily Close.  However, ensure that any incident that will get caught by the query has the relevant action available at that status.

     

    The schedules are performed by the Touchpaper Background Processing service so the action will be created by SYSTEM and the service must be running.

     

    Using this method from a Read Only status

    The method above requires being able to set the AutoClose Flag attribute on the Incident at the status it is sitting at.  However if the status is configured to be Read Only this is not possible.  For details on the variations required to make this work please see the following document: Using the autoclose calculation from a Read Only status