:: Version 3.2.0 ::
Close UserRequest on associated Change closure
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 UserRequest that a
related to a change when this one is closed Limitation: The samples XML provided work only with the
option itop-change-mgmt
and not
itop-change-mgmt-ITIL
What do we need to do for this:
-
Add a method to perform the apply stimulus
ev_autoresolve
on each related request -
Use this method as an action when the change is closed
Computing method
Alter the class Change to add the following PHP method
- class Change
-
/** * * @return bool Return true on success or false to prevent the transition to happen */ public function ResolveRelatedRequest() { $sOQL = "SELECT UserRequest WHERE parent_change_id = :ticket AND status != 'resolved'"; $oRelatedRequestSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL), array(), array('ticket' => $this->GetKey())); while($oRequest = $oRelatedRequestSet->Fetch()) { if ($oRequest->Get('status') != 'resolved' && $oRequest->Get('status') != 'closed' ) { $oRequest->Set('solution', 'ticket automatically resolved by '.$this->Get('friendlyname')); $oRequest->ApplyStimulus('ev_autoresolve'); $oRequest->DBUpdate(); } } }
Alter the Change Worflow
To execute this method when a change is closed, you have to alter the workflow of the Change class.
- itop-design / classes / class@Change
-
<lifecycle> <states> <state id="approved" _delta="must_exist"> <transitions> <transition id="ev_finish" _delta="must_exist"> <actions _delta="redefine"> <action> <verb>SetCurrentDate</verb> <params> <param xsi:type="attcode">close_date</param> </params> </action> <action> <verb>ResolveRelatedRequest</verb> </action> </actions> </transition> </transitions> </state> </states> </lifecycle>
Because the XML tag
<action> has no
id
you must redefine the full
list of actions executed during this transitionComplete XML Delta
<class id="Change" _delta="must_exist"> <methods> <method id="ResolveRelatedRequest" _delta="define"> <comment>/** * * @author My first name My last name * @return bool Return true on success or false to prevent the transition to happen */</comment> <static>false</static> <access>public </access> <code><![CDATA[ public function ResolveRelatedRequest() { $sOQL = "SELECT UserRequest WHERE parent_change_id = :ticket AND status != 'resolved'"; $oRelatedRequestSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL), array(), array('ticket' => $this->GetKey())); while($oRequest = $oRelatedRequestSet->Fetch()) { if ($oRequest->Get('status') != 'resolved' && $oRequest->Get('status') != 'closed' ) { $oRequest->Set('solution', 'ticket automatically resolved by '.$this->Get('friendlyname')); $oRequest->ApplyStimulus('ev_autoresolve'); $oRequest->DBUpdate(); } } return true; }]]></ code> <arguments/> </method> </methods> <lifecycle> <states> <state id="approved" _delta="must_exist"> <transitions> <transition id="ev_finish" _delta="must_exist"> <actions _delta="redefine"> <action> <verb>SetCurrentDate</verb> <params> <param xsi:type="attcode">close_date</param> </params> </action> <action> <verb>ResolveRelatedRequest</verb> </action> </actions> </transition> </transitions> </state> </states> </lifecycle> </class>
3_2_0/customization/cascade-change-closure.txt ยท Last
modified: 2024/09/10 10:25 by 127.0.0.1