Using the autoclose calculation from a Read Only status

Version 2

    The document Using Calculations to replace and enhance AutoClose (or automatically move any process on to any status with any action) gives full instructions on setting up a calculation to automatically perform a process action such as Close after a set period of time.  However it assumes that the status you are moving from is not configured to be Read Only.  The calculation that is performed each night to check if the process is ready to move on can't run if the status is Read Only so an alternative method is needed.

     

    The following are the variations to the steps on the document linked above.  Follow the steps as normal but refer to this document for the changes.  It is assumed you are using Incidents and checking against the Resolutions collection as in the example in the original document.

     

    Stage 1 - The Scheduled Calculation
    • Step 1 instructs you to create a Boolean attribute on the Incident however in this case you should instead create it on the Resolution object.  This is because the Resolution object is what is being checked against in the calculation, and while the Incident itself is Read Only the collection object is not.

     

    • Step 4 has an example calculation.  Instead use the following:

     

    import System
    static def GetAttributeValue(Resolution):
     // initially set the flag to False
     Flag = 'False'
     
     // check this is the latest resolution and otherwise return False
     if Resolution.SerialNumber != Resolution.Incident.Resolutions.Count:
      return Flag
    
     // check the incident is resolved
     if Resolution.Incident.Status.Name == 'Resolved':
     
      // check if this resolution was over 7 days ago
      TimeSinceResolved = Resolution.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 main difference is that before checking if the resolution was created over a week ago it also checks that this is the latest resolution.  This is because you could have re-opened and re-resolved an incident multiple times and when the action is performed on the Incidents with the flag enabled we need to know that the time elapsed since it was resolved is from the most recent resolution.

     

    Stage 2 - Scheduling the calculation
    • Step 2 instructs you to create a query on the Incident object.  Instead create it on the Resolution object as this is where the calculation attribute sits.
    • For adding the criteria in step 3 you need to expand the relationship to Incident in the attributes list to access the Status.
    • In step 4 in creating the schedule set the object to Resolution rather than Incident.

     

    Stage 3 - Schedule the Close action
    • For adding the criteria in step 2 you need to expand the Resolutions collection in the attributes list to access the AutoClose Flag attribute created in the first stage.

     

    Because the criteria is based on a collection this would return incidents where any of the resolutions has the flag set.  However this is not an issue because the calculation only sets the flag if the resolution is the latest for that Incident and clears the flag on previous resolutions.