Close Ticket automatically after a delay
Prerequisite: You must be familiar with the Syntax used in Tutorials and have already created an extension.
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:
-
Add a Stopwatch with threshold(s) and goal
-
Write the Computing method
-
Define Trigger and Notifications on your iTop instance, if you want to notify the customer before automatically closing the ticket
-
Restart the counter from scratch if the customer replies and the ticket exits the
frozen
state.
Add Stopwatch
-
Add a Stopwatch field on the UserRequest class
-
Define the states during which the Stopwatch will be running
-
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
. -
Define threshold(s), here I defined three so I can use them later in trigger and notifications.
-
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.
-
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>
latest/customization/auto-close.txt
ยท Last modified: 2024/09/10 10:25 by 127.0.0.1