You are browsing the documentation for iTop 3.0 which is not the current version.

Consider browsing to iTop 3.1 documentation

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
  4. Restart the counter from scratch if the customer replies and the ticket exits the frozen state.

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

With the above example you can create Trigger (on threshold) and action when the User Request reach 33%, 66% or 100% of the goal. This means you can have different email content at different level of the threshold.

Restart the counter

On any transition exiting the frozen state, you may want to reset the counter.

classes / class@UserRequest / lifecycle / states
          <state id="frozen" _delta="define">
            <flags>...</flags>
            <transitions>
              <!-- more transitions -->
              <transition id="ev_autoresolve">
                <stimulus>ev_autoresolve</stimulus>
                <target>resolved</target>
                <actions>
                  <action>
                    <verb>ResetStopWatch</verb>
                    <params>
                      <param xsi:type="attcode">pending_customer_stopwatch</param>
                    </params>
                  </action>
                  <!-- more actions -->
                </actions>
              </transition>
            </transitions>
          </state>
3_0_0/customization/auto-close.txt ยท Last modified: 2022/03/29 16:43 (external edit)
Back to top
Contact us