从工单移除字段

决条件:您必须熟悉教程中使用的语法 并且已经创建了一个扩展.

学习:从类删除现有字段

水平:中间

域:XMLPHPprotalLifecycle, prsentation

最低版本:2.1.0

为了删除字段,必须标识iTop XML数据模型中使用该字段的所有位置。为此,在添加扩展之前,请打开已安装的iTop的data/datamodel-production.xml文件。将其保存为引用。

对于UserRequest类的紧急度字段,您至少应删除此列表中的所有外观:

  • itop_design / classes / class@UserRequest / fields / field@urgency

  • itop_design / classes / class@UserRequest / properties (naming, order, reconciliation, …)

  • itop_design / classes / class@UserRequest / lifecycle

  • itop_design / classes / class@UserRequest / presentation

  • itop_design / classes / class@UserRequest / methods

  • itop_design / module_designs / module_design@itop-portal / forms

  • itop_design / module_designs / module_design@itop-portal / classes / class@UserRequest

例如,某些字段必须在不破坏iTop的情况下才能删除。

  • 任何类的org_id字段,
  • 具有生命周期的任何类的status字段
  • 工单上的caller_id字段
  • 还有更多的领域,但这是一个好的开始

从iTop的标准数据模型中删除现有字段可能会破坏与iTop扩展的兼容性,后者将依赖于删除字段。

只是躲田野

您可以决定仅隐藏用户的字段。在某些情况下,这可能就足够了。

隐藏没有默认价值的必填字段不起作用。

  • 创建后,提交将失败
  • 如果转换中的字段为必填,则转换中将提示输入表单

隐藏在门户中

字段仅对于门户用户可以隐藏,因为门户中使用的表单是以XML定义的,并且独立于控制台。

这是在工单创建时如何将其隐藏的方法:

itop_design / module_designs / module_design@itop-portal / forms
 
<form id="ticket-create" _delta="must_exist">
  <twig _delta="redefine">
    <div class="row">
      <div class="col-sm-6">
        <div class="form_field" data-field-id="service_id" data-field-flags="mandatory"></div>
      </div>
      <div class="col-sm-6">
        <div class="form_field" data-field-id="servicesubcategory_id" data-field-flags="mandatory"></div>
      </div>
    </div>
    <div id="service_details_placeholder">
      <div class="form_field" data-field-id="service_details"></div>
    </div>
    <div class="row">
      <div class="col-sm-6">
        <div class="form_field" data-field-id="impact"></div>
      </div>
      <div class="col-sm-6">
      <!-- lines to be removed from default Portal
        <div class="form_field" data-field-id="urgency"></div>
      -->
      </div>
    </div>
    <div>
      <div class="form_field" data-field-id="title"></div>
      <div class="form_field" data-field-id="description"></div>
      <div class="form_field" data-field-id="contacts_list"></div>
    </div>
  </twig>
</form>

更改此“细枝”,还可以将工单的创建方式显示为变更,并将其显示为用户

这是如何在工单版上将其隐藏:

itop_design / module_designs / module_design@itop-portal / forms
 
<form id="ticket-edit" _delta="must_exist">
  <twig _delta="redefine">
    <div class="row">
      <div class="col-sm-7">
        <fieldset>
          <legend>{{'Ticket:baseinfo'|dict_s}}</legend>
          <div class="col-sm-6">
            <div class="form_field" data-field-id="title" data-field-flags="read_only"/>
            <div class="form_field" data-field-id="service_id" data-field-flags="read_only"/>
          </div>
          <div class="col-sm-6">
            <div class="form_field" data-field-id="caller_id" data-field-flags="read_only"/>
            <div class="form_field" data-field-id="servicesubcategory_id" data-field-flags="read_only"/>
          </div>
          <div class="col-sm-12">
            <div class="form_field" data-field-id="description" data-field-flags="read_only"/>
            <div class="form_field" data-field-id="solution" data-field-flags="read_only"/>
          </div>
          <div class="col-sm-6">
            <div class="form_field" data-field-id="user_satisfaction" data-field-flags="read_only"/>
          </div>
          <div class="col-sm-6">
            <div class="form_field" data-field-id="user_comment" data-field-flags="read_only"/>
          </div>
        </fieldset>
      </div>
      <div class="col-sm-5">
        <fieldset>
          <legend>{{'Ticket:Type'|dict_s}} &amp; {{'Ticket:date'|dict_s}}</legend>
          <div class="col-sm-6">
            <div class="form_field" data-field-id="status" data-field-flags="read_only"/>
            <div class="form_field" data-field-id="impact" data-field-flags="read_only"/>
            <!-- <div class="form_field" data-field-id="urgency" data-field-flags="read_only"/> -->
            <div class="form_field" data-field-id="priority" data-field-flags="read_only"/>
          </div>
          <div class="col-sm-6">
            <div class="form_field" data-field-id="start_date" data-field-flags="read_only"/>
            <div class="form_field" data-field-id="last_update" data-field-flags="read_only"/>
            <div class="form_field" data-field-id="resolution_date" data-field-flags="read_only"/>
            <div class="form_field" data-field-id="agent_id" data-field-flags="read_only"/>
          </div>
        </fieldset>
      </div>
    </div>
    <div>
      <div class="form_field" data-field-id="contacts_list"/>
      <div class="form_field" data-field-id="public_log"/>
    </div>
  </twig>
</form>

以上表格仅是特定安装的iTop 2.6的示例。

隐藏在控制台中

可以将其隐藏在控制台中的详细说明中

  • 这对门户没有影响
itop_design / classes / class@UserRequest
 
    <!-- Display the 2 new fields in the details of the UserRequest -->
    <presentation>
      <details _delta="must_exist">
        <items>
          <!-- Second column of the UserRequest display -->
          <item id="col:col2">
            <items>
              <!-- id of the fieldset should be found in datamodel-production.xml file -->
              <item id="fieldset:Ticket:Type">
                <items>
                  <!-- remove the urgency -->
                  <item id="urgency" _delta="delete"/>
                </items>
              </item>
            </items>
          </item>
        </items>
      </details>
    </presentation>

这不能完全删除该字段,因为仍然可以通过

  • CSV导出,
  • 通过“配置此列表...”菜单在列表中
  • CSV导入
  • API REST/JSON

删除领域

栏位定义

现在,我们想从该类对象中完全删除该字段,这意味着也从数据库中删除它。我们需要从类中删除该字段:

itop_design / classes / class@UserRequest / fields
 
        <field id="urgency" _delta="delete">
        </field>

类属性

我们需要检查紧急度字段是否用于:

  • UserRequest友好名称
  • CSV导入使用的UserRequest对帐字段
  • UserRequest废弃逻辑
  • UserRequest唯一性规则

既然不是这种情况,我们无事可做。否则我们将不得不变更。

生命周期标志

我们需要在类的生命周期中将该字段删除任何引用。对于紧急度,仅在状态被解决上设置标志,因此只有一个XML节点要设置为“删除”:

itop_design / classes / class@UserRequest / lifecycle / states
 
   <state id="resolved">
      <flags>
        <attribute id="urgency" _delta="delete"/>
      </flags>
   </state>

方法

我们需要删除UserRequest类上定义的PHP方法中该字段的所有引用

itop_design / classes / class@UserRequest / methods
 
   <method id="xxx">
      <code>
      <!-- check the PHP of each method as they could be relying on this code attribute -->
      </ code>
   </method>

要标识受影响的PHP方法,请使用代码属性的搜索

例如,到$ this→Get('紧急度')的任何引用(其中$ this是UserRequest)都会使iTop崩溃,并显示FatalError

UserRequest方法中紧急度搜索的结果导致产生ComputePriority方法,需要对其进行修改:

class:UserRequest
 

public function ComputePriority() { // priority[impact][urgency] $aPriorities = ( // a department 1 => ( 1 => 1, 2 => 1, 3 => 2, 4 => 4, ), // a group 2 => ( 1 => 1, 2 => 2, 3 => 3, 4 => 4, ), // a person 3 => ( 1 => 2, 2 => 3, 3 => 3, 4 => 4, ), ); $iPriority = 1; if (($aPriorities[(int)$this->Get('impact')]) && ($aPriorities[(int)$this->Get('impact')][(int)$this->Get('urgency')])) { $iPriority = $aPriorities[(int)$this->Get('impact')][(int)$this->Get('urgency')]; } return $iPriority; }

介绍

由于此紧急度字段也用于表单定义中,因此您必须应用上述2项更改,也就是说,应在门户表单和演示文稿详细信息中将其删除。但这还不够,也许在演示文稿的其他部分中指定了该字段,例如搜索,list和default_搜索

在我们的例子中,紧急度仅在搜索标准中定义,因此我们将其删除:

itop_design / classes / class@UserRequest
 
    <presentation>
      <search>
        <items>
          <!-- remove the urgency -->
          <item id="urgency" _delta="delete"/>
        </items>
      </details>
    </presentation>

辞典

从理论上讲,我们还应该删除相应的字典条目,但不要这样做,因为它对iTop行为没有影响。

OQL查询

删除的字段可用于存储的OQL查询中

  • 在DataModel中:例如在外部密钥的过滤器标签上,…
  • 在Dashlet中:在数据模型或用户偏好中定义
  • 在QueryPhrases中
  • 在审计规则中
  • 在包含过滤器的书签URL中
  • 在通知中
  • 配置文件中的参数
  • 扩展带给的其他地方

删除父类上的字段

在抽象类上删除字段时,必须在抽象类及其所有子类上完成XML中搜索的用法。

原贴链接:https://www.itophub.io/wiki/page?id=2_7_0%3Acustomization%3Aremove-field


Remove a field from Ticket

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

learning:
Remove an existing field from a class
level:
Intermediate
domains:
XMLPHPPortalLifecyclePresentation
min version:
2.1.0

In order to remove a field, you must identify all the places where that field is used within the iTop XML datamodel. For this open the /data/datamodel-production.xml file of an installed iTop, before adding your extension. Save it somewhere as the reference.

For the urgency field of the UserRequest class, you should at least remove any appearance in this list:

  • itop_design / classes / class@UserRequest / fields / field@urgency

  • itop_design / classes / class@UserRequest / properties (naming, order, reconciliation, …)

  • itop_design / classes / class@UserRequest / lifecycle

  • itop_design / classes / class@UserRequest / presentation

  • itop_design / classes / class@UserRequest / methods

  • itop_design / module_designs / module_design@itop-portal / forms

  • itop_design / module_designs / module_design@itop-portal / classes / class@UserRequest

Some fields cannot be removed without breaking iTop, for example

  • org_id field on any class,

  • status field on any class with a lifecycle

  • caller_id field on Ticket

  • there are more fields, but that's a good start

Removing an existing field from the standard datamodel of iTop can break compatibilities with iTop extensions which would rely on the remove field.

Just hiding the field

You can decide just to hide the field to the user. In some case, it can be enough.

Hiding a mandatory field with no default value does not work.

  • On creation, submission will fail

  • If the field in mandatory within a transition, field will be prompt in transition form

Hiding in the Portal

A field can be hidden just for Portal User, as the forms used in a Portal are defined in XML and are independent from the Console one.

This is how to hide it on Ticket creation:

itop_design / module_designs / module_design@itop-portal / forms
 
<form id="ticket-create" _delta="must_exist">
  <twig _delta="redefine">
    <div class="row">
      <div class="col-sm-6">
        <div class="form_field" data-field-id="service_id" data-field-flags="mandatory"></div>
      </div>
      <div class="col-sm-6">
        <div class="form_field" data-field-id="servicesubcategory_id" data-field-flags="mandatory"></div>
      </div>
    </div>
    <div id="service_details_placeholder">
      <div class="form_field" data-field-id="service_details"></div>
    </div>
    <div class="row">
      <div class="col-sm-6">
        <div class="form_field" data-field-id="impact"></div>
      </div>
      <div class="col-sm-6">
      <!-- lines to be removed from default Portal
        <div class="form_field" data-field-id="urgency"></div>
      -->
      </div>
    </div>
    <div>
      <div class="form_field" data-field-id="title"></div>
      <div class="form_field" data-field-id="description"></div>
      <div class="form_field" data-field-id="contacts_list"></div>
    </div>
  </twig>
</form>

Changing this “twig” allow you also to change the way the Ticket is displayed on creation to the user

And this is how to hide it on Ticket Edition:

itop_design / module_designs / module_design@itop-portal / forms
 
<form id="ticket-edit" _delta="must_exist">
  <twig _delta="redefine">
    <div class="row">
      <div class="col-sm-7">
        <fieldset>
          <legend>{{'Ticket:baseinfo'|dict_s}}</legend>
          <div class="col-sm-6">
            <div class="form_field" data-field-id="title" data-field-flags="read_only"/>
            <div class="form_field" data-field-id="service_id" data-field-flags="read_only"/>
          </div>
          <div class="col-sm-6">
            <div class="form_field" data-field-id="caller_id" data-field-flags="read_only"/>
            <div class="form_field" data-field-id="servicesubcategory_id" data-field-flags="read_only"/>
          </div>
          <div class="col-sm-12">
            <div class="form_field" data-field-id="description" data-field-flags="read_only"/>
            <div class="form_field" data-field-id="solution" data-field-flags="read_only"/>
          </div>
          <div class="col-sm-6">
            <div class="form_field" data-field-id="user_satisfaction" data-field-flags="read_only"/>
          </div>
          <div class="col-sm-6">
            <div class="form_field" data-field-id="user_comment" data-field-flags="read_only"/>
          </div>
        </fieldset>
      </div>
      <div class="col-sm-5">
        <fieldset>
          <legend>{{'Ticket:Type'|dict_s}} &amp; {{'Ticket:date'|dict_s}}</legend>
          <div class="col-sm-6">
            <div class="form_field" data-field-id="status" data-field-flags="read_only"/>
            <div class="form_field" data-field-id="impact" data-field-flags="read_only"/>
            <!-- <div class="form_field" data-field-id="urgency" data-field-flags="read_only"/> -->
            <div class="form_field" data-field-id="priority" data-field-flags="read_only"/>
          </div>
          <div class="col-sm-6">
            <div class="form_field" data-field-id="start_date" data-field-flags="read_only"/>
            <div class="form_field" data-field-id="last_update" data-field-flags="read_only"/>
            <div class="form_field" data-field-id="resolution_date" data-field-flags="read_only"/>
            <div class="form_field" data-field-id="agent_id" data-field-flags="read_only"/>
          </div>
        </fieldset>
      </div>
    </div>
    <div>
      <div class="form_field" data-field-id="contacts_list"/>
      <div class="form_field" data-field-id="public_log"/>
    </div>
  </twig>
</form>

The above forms are just examples from a particular installation of iTop 2.6.

Hiding in the Console

It can be hidden just in the Console, in the details presentation

  • This has no effect on the Portal

itop_design / classes / class@UserRequest
 
    <!-- Display the 2 new fields in the details of the UserRequest -->
    <presentation>
      <details _delta="must_exist">
        <items>
          <!-- Second column of the UserRequest display -->
          <item id="col:col2">
            <items>
              <!-- id of the fieldset should be found in datamodel-production.xml file -->
              <item id="fieldset:Ticket:Type">
                <items>
                  <!-- remove the urgency -->
                  <item id="urgency" _delta="delete"/>
                </items>
              </item>
            </items>
          </item>
        </items>
      </details>
    </presentation>

This does not fully remove the field, as it is still available through

  • CSV export,

  • in list though “Configure This List…” menu

  • CSV import

  • API REST/JSON

Removing the field

Field definition

Now we would like to completely removed the field from that class of object, which means also remove it from database. We need to remove the field from the class:

itop_design / classes / class@UserRequest / fields
 
        <field id="urgency" _delta="delete">
        </field>

Class properties

We need to check if the urgency field is used in:

  • the UserRequest friendlyname

  • the UserRequest reconciliation fields used for CSV import

  • the UserRequest obsolescence logic

  • the UserRequest uniqueness rules

As it's not the case here, we have nothing to do; otherwise we would have had to change them.

Lifecycle flags

We need to remove any reference to that field in the lifecycle of the class. In the case of urgency, flags are only set on state resolved, so just one XML node to set to “delete”:

itop_design / classes / class@UserRequest / lifecycle / states
 
   <state id="resolved">
      <flags>
        <attribute id="urgency" _delta="delete"/>
      </flags>
   </state>

Methods

We need to remove any reference to that field in the PHP methods defined on the UserRequest class

itop_design / classes / class@UserRequest / methods
 
   <method id="xxx">
      <code>
      <!-- check the PHP of each method as they could be relying on this code attribute -->
      </ code>
   </method>

To identify impacted PHP method, search for the code attribute

For example any reference to $this→Get('urgency') where $this is a UserRequest would crash iTop with a FatalError

The result of the urgency search within UserRequest methods, leads to ComputePriority method which need to be modified:

class:UserRequest
 

public function ComputePriority() { // priority[impact][urgency] $aPriorities = ( // a department 1 => ( 1 => 1, 2 => 1, 3 => 2, 4 => 4, ), // a group 2 => ( 1 => 1, 2 => 2, 3 => 3, 4 => 4, ), // a person 3 => ( 1 => 2, 2 => 3, 3 => 3, 4 => 4, ), ); $iPriority = 1; if (($aPriorities[(int)$this->Get('impact')]) && ($aPriorities[(int)$this->Get('impact')][(int)$this->Get('urgency')])) { $iPriority = $aPriorities[(int)$this->Get('impact')][(int)$this->Get('urgency')]; } return $iPriority; }

Presentation

As this urgency field is used also in the forms definitions, you must apply the 2 changes described above, as to say, deleting it in the Portal forms and in the presentation details. But this is not enough, maybe that field was specified in other part of the presentation, such as search, list and default_search

In our case, urgency was only defined in the search criterion, so we remove it:

itop_design / classes / class@UserRequest
 
    <presentation>
      <search>
        <items>
          <!-- remove the urgency -->
          <item id="urgency" _delta="delete"/>
        </items>
      </details>
    </presentation>

Dictionaries

In theory, we should also delete the corresponding dictionary entries, but not doing it as no effect on iTop behavior.

OQL queries

The removed field can be used in OQL queries stored

  • in the DataModel: for example on filter tag of External Keys,…

  • in Dashlets: defined in the datamodel or in user preferences

  • in QueryPhrases

  • in Audit rules

  • in bookmarked urls containing a Filter

  • in Notifications

  • in Configuration file parameters

  • and other places brought by extensions

Removing field on parent class

When removing a field on an abstract class, the search of usage within the XML must be done on the abstract class and all its sub-classes.

标签:
由 superadmin 在 2020/08/27, 17:15 创建
    

需要帮助?

如果您需要有关XWiki的帮助,可以联系:

深圳市艾拓先锋企业管理咨询有限公司