:: Version 2.7.0 ::

Close Ticket automatically after a delay

Prerequisite: You must be familiar with the Syntax used in Tutorials and have already created an extension.

learning:
Close Ticket automatically after a delay
level:
Medium
domains:
XML, PHP, Lifecycle
min version:
2.3.0

Let's assume we want to automatically close Ticket which are in frozen state for more than 21 days

What do we need to do for this:

  1. Add a Stopwatch with threshold(s) and goal
  2. Write the Computing method
  3. Define Trigger and Notifications on your iTop instance, if you want to notify the customer before automatically closing the ticket

Add Stopwatch

  1. Add a Stopwatch field on the UserRequest class
  2. Define the states during which the Stopwatch will be running
  3. Considering that the Delay of 21 days does not need to care about neither business hours nor week-ends & vacations, we use 24*7 coverage window, which is the default. Its code is DefaultWorkingTimeComputer.
  4. Define threshold(s), here I defined three so I can use them later in trigger and notifications.
  5. On 100% Threshold, which is when the goal is reached, I force the UserRequest to close it-self, which will stop the stopwatch as the UserRequest will no more be in a state where the stopwatch is running.
  6. Set a goal

Put this in a datamodel.my-extension.xml file of your extension

classes / class@UserRequest / fields
        <field id="pending_customer_stopwatch" xsi:type="AttributeStopWatch" _delta="define">
          <states>
            <state id="frozen">frozen</state>
          </states>
          <working_time>DefaultWorkingTimeComputer</working_time>
          <thresholds>
            <threshold id="33">
              <actions/>
            </threshold>
            <threshold id="66">
              <actions/>
            </threshold>
            <threshold id="100">
              <actions>
                <action>
                  <verb>ApplyStimulus</verb>
                  <params>
                    <param xsi:type="string">ev_resolve</param>
                  </params>
                </action>
              </actions>
            </threshold>
          </thresholds>
          <always_load_in_tables>true</always_load_in_tables>
          <goal>ComputePendingDelay</goal>
        </field>

Computing method

Put this in a main.my-extension.php of your extension

  class ComputePendingDelay implements iMetricComputer
{
    public static function GetDescription()
    {       
            return "Used to compute delay when pending caller";
    }
    public function ComputeMetric($oObject)
    {
        // Set the delay as a configuration parameter if you wish or hardcode it.
        $iDelay = MetaModel::GetModuleSetting('itop-request-mgmt', 'pending_delay', '21'); 
        $iRes = $iDelay*86400;  // $iDelay in days * 86400 seconds within one day
        return $iRes;
     }
}

Define Notifications

FIXME to be added

2_7_0/customization/auto-close.txt ยท Last modified: 2020/06/11 16:57 (external edit)
Back to top
Contact us