Progressing a process: Auto Close

This example demonstrates how to use a scheduled calculation to move a process from one status to another. Specifically, it demonstrates how to move an Incident that has been Resolved for 40 hours to the Closed status. You can modify it so that it works in other modules, or to move between different statuses. For example, you could modify the calculation to return Calls that have been at the status With Customer for a certain time.

There are three stages to this calculation:

  1. Set up the scheduled calculation
  2. Schedule the calculation
  3. Schedule a bulk action to change the status of the appropriate processes

The first stage is to set up a calculation that tests to see if the Incident is ready to be closed. In stage 2 we will configure this to be calculated every night, but first we need to create a check box to store our calculation result.

To set up the scheduled calculation:
  1. In Object Designer, create a boolean attribute on the Incident Management\Incident object called AutoClose.
  2. In the Properties grid, set the Default Value to False.
  3. In the Properties grid, set the Calculation Type to Scheduled.
    The Edit Formula dialog appears.
  4. Type the following into the Editor field:
import System
static def GetAttributeValue(Incident):
 Flag = 'False'
 
 if Incident.Status.Name == 'Resolved':
 
  Resolution = Incident.Resolutions.Latest()
  TimeSinceResolved = Incident.GetBusinessTime(Resolution.CreationDate, DateTime.UtcNow)
  if TimeSinceResolved.TotalHours > 40:
 
   if DateTime.Today.DayOfWeek != DayOfWeek.Saturday and DateTime.Today.DayOfWeek != DayOfWeek.Sunday:
    Flag = 'True'
 
 return Flag

The first two lines have no indents. The line Flag = 'False' and the first line starting if have single indents. The lines from Resolution through to the second if have two indents. The line with the third if has three indents, and the line below it (Flag = 'True') has four indents. The final line (return Flag) has a single indent.

Initially, the flag is set to False, and then the calculation tests to see if the Incident is at the status Resolved. If the Incident is resolved, the calculation moves to the next section of the calculation.

Resolution = Incident.Resolutions.Latest() uses the collection function Latest() to return the Incident Resolution that has the latest creation date. We can then use Resolution.CreationDate in the next line of the calculation to give us the creation date of the latest resolution.

TimeSinceResolved = Incident.GetBusinessTime(Resolution.CreationDate, DateTime.UtcNow) uses the GetBusinessTime Object Function to determine the difference in business hours between the creation date of the latest resolution (Resolution.CreationDate), and the current time in UTC (the DateTime function DateTime.UtcNow) based on the calendar used by the Incident’s response level. (Most DateTimes in the database are stored in UTC.)

If this value is greater than 40 (1 working week = 5 x 8 = 40 hours), then the calculation tests that the day of the week is not equal to (!=) Saturday and not equal to Sunday. If this test is passed, it sets the flag to True.

The final line of the calculation returns the value of the flag as the value for the AutoClose attribute.

You can change this calculation to move a process from statuses other than Resolved by changing the status and collection that are used. For example, by using the With Customer status and collection, you could return processes to the analyst that have been with a customer for a certain period.

The next stage is to schedule the calculation to run. The schedule needs a query of incidents to test, so we also need to create this.

To create a schedule for the calculation:
  1. In Query and Report Designer, create a new system query based on Incident Management\Incident called Resolved Incidents.
  2. Set the criteria to Status Is Equal To ( Resolved ), and save it.
  3. In Schedule Manager on the Bulk Action Management tree, click New Scheduled Bulk Action in the Actions list.
  4. In the Name box, type AutoClose Calculation.
  5. Set the schedule to run Daily at an appropriate time (usually out of hours).
  6. In the Module list select Incident Management, in the Business Object list select Incident, and in the Query list select Resolved Incidents (the query we just created).
  7. In the Scheduled Action Type list, select Perform Calculation.
  8. Click Calculations.
    The Select calculation attributes that you want calculated dialog appears.
  9. Move our AutoClose attribute to the Selected Calculation Attributes list, then click OK.
  10. Click to save the schedule.

The scheduled calculation that we have just created sets a flag on the Incident to True, but doesn't actually close the Incident. To do that we need to schedule a bulk action to close any Incidents that have the flag set to True. First, we need to create a query to select the correct Incidents.

To schedule the Close action:
  1. In Query and Report Designer, copy the Resolved Incidents query and rename it Resolved Incidents to AutoClose.
  2. Add a second criteria of:
    AND AutoClose Is Equal To ( True ).
    Now we can create the schedule.
  3. Create a new Scheduled Bulk Action as before and name it AutoClose Action.
  4. Set the schedule to run Daily as before, but 30 minutes after the calculation schedule that we created previously.
    We need the scheduled action that calculates and sets the AutoClose flags on the Incidents to complete before we run this scheduled action that then closes the flagged Incidents.
  5. In the Module list select Incident Management, in the Business Object list select Incident, and in the Query list select Resolved Incidents to AutoClose.
  6. In the Scheduled Action Type list, select Run Action.
  7. In the Action list, select Close.
  8. Click Window Data.
    The Closure window appears.
  9. Complete the Closure window as you require, then click .
    The schedule is saved.

You can use this technique for any action, not just Close. However, make sure that the processes selected by the query have the relevant action available at that status.


Was this article useful?    

The topic was:

Inaccurate

Incomplete

Not what I expected

Other