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

Consider browsing to iTop 3.1 documentation

Force a field to be mandatory by lifecycle

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

learning:
Force a field to be filled on some state/transition
level:
Intermediate
domains:
XML, PHP, Constrain, Lifecycle
min version:
2.1.0

This use case is just one way of forcing a field to be provided.

For those use cases, we will use UserRequest class, because it has a lifecycle. When an object has a lifecycle, iTop datamodel allow to specify on a Transition and on a State which fields must be required.

Flags on lifecycle applies to Console and Portal, but do not force the field to be provided when object is created/modified using CSV import, DataSynchro or API REST/JSON

Mandatory on transition

For example, you may decide that a Service must be documented when a User Request is moved from state New to state Assigned.
That move is called a transition and is uniquely identified by the initial state and the stimulus applied.

itop_design / classes
    <class id="UserRequest">
      <lifecycle>
        <states>
          <!-- For User Request in State New... -->
          <state id="new">
            <transitions>
              <!-- On the transition, trigger by ev_assign stimulus... -->
              <transition id="ev_assign" _delta="must_exist">
                <flags>
                  <!-- We want to force the Service... -->
                  <attribute id="service_id" _delta="define" >
                    <!-- to be provided -->
                    <mandatory/>
                  </attribute>
                </flags>
              </transition>
            </transitions>
          </state>
        </states>
      </lifecycle>
    </class>

Mandatory on a state

In this usecase we want to be sure that all UserRequest in state Assigned have a Service defined.

When the “mandatory” flag is defined at the state level, then it automatically applies to all transitions ending on that state, even if not specified at the transition level.
itop_design / classes
    <class id="UserRequest" _created_in="itop-request-mgmt-itil" _delta="must_exist">
      <lifecycle>
        <states>
          <state id="assigned" _delta="must_exist">
            <!-- setting no _delta is equivalent to _delta="merge" -->
            <flags>
              <!-- Here we assume that no other extension nor the default datamodel... -->
              <!-- has set flags on field 'service-id' for state 'assigned' already -->
              <attribute id="service_id" _delta="define>
                <mandatory/>
              </attribute>
            </flags>
          </state>
        </states>
      </lifecycle>
    </class>

Migration: No visible effect on setup, but objects not compliant can no more be modified in the Console or Portal, until a Service is provided. Create an audit rule to retrieve objects not compliant to this new constrain and fix them.

2_7_0/customization/mandatory-on-transition.txt · Last modified: 2020/04/15 15:23 (external edit)
Back to top
Contact us