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

Consider browsing to iTop 3.2 documentation

Close UserRequest on associated Change closure

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

learning:
Close UserRequest related to a Change when this one is closed
level:
Medium
domains:
XML, PHP, Lifecycle
min version:
2.3.0

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:

  1. Add a method to perform the apply stimulus ev_autoresolve on each related request
  2. 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 transition

Complete 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_0_0/customization/cascade-change-closure.txt ยท Last modified: 2022/01/21 16:52 by 127.0.0.1
Back to top
Contact us