二次开发-调整工单
统计工单重开次数
先决条件:您必须熟悉教程中使用的语法 并且已经创建了一个扩展.
学习:计数过渡发生
水平:[ ttps://]初学者
域:[ ttps://]XML, [ ttps://]PHP, [ ttps://]Automation, [ ttps://]Dictionary, [ ttps://]Lifecycle
最低版本:2.1.0
在此用例中,我们要计数重新打开用户请求的次数。为此:
向UserRequest添加一个计数器字段,
停用历史记录跟踪(可选)
在UserRequest上定义PHP方法以增加计数器,
修改UserRequest生命周期以在转换期间将方法从被解决调用为已分配
修改演示文稿以显示计数器
为计数器字段添加标签
为了提高可读性,我们用6个不同的XML块介绍了这6个步骤,但是实际上,您只需要编写一个XML结构即可。
iTop XML编译流程,支持具有重复节点的非最佳树结构,他将合并它们
[ ttps://]itop_design <classes> <class id="UserRequest" _delta="must_exist"> <fields> <field id="reopen_count" xsi:type="AttributeInteger" _delta="define"> <sql>reopen_count</sql> <default_value>0</default_value> <is_null_allowed>true</is_null_allowed> </field> </fields> </class> </classes>
停用历史记录跟踪
每次更改reopen_计数计数器时,您都可以确定它对历史记录中的记录毫无用处
然后将<tracking_level> none << tracking_level>添加到字段定义中,它将完成此工作。这只是一个选择,您不必这样做。如果您未定义标签,则iTop将跟踪在该字段上所做的更改,因为省略时它是默认设置。
<field id="reopen_count"> <!-- No tracking level, mean no entry in History log for this field --> <tracking_level>none</tracking_level> </field>
删除字段上的历史记录跟踪可以避免污染对象历史记录。
不断变化的价值,由外部来源掌握
计算的计数器,其修改日期可能没有用
[ ttps://]class:UserRequest public function IncrementCounter($sAttCode, $iIncrement=1) { // Defensive programming, ensure that: the field code is valid on current class if (MetaModel::IsValidAttCode(($this), $sAttCode) // and the increment provided is numeric && ($iIncrement) // and the field code correspond to an Integer type of attribute && (MetaModel::GetAttributeDef(($this),$sAttCode) instanceof AttributeInteger)) { $iNew = $this->Get($sAttCode) + $iIncrement; $this->Set($sAttCode, $iNew); } return true; }
请记住,PHP方法需要嵌入到
[ :8082/bin/view/5/5.4/#insert_a_php_method]每次工单从被解决移到分配的状态时,我们就增加计数器。
<!-- When we are in "resolved" state of UserRequest lifecycle --> <state id="resolved"> <!-- We look at the possible transitions from that state --> <transitions> <!-- if an "ev_reopen" stimulus is applied --> <transition id="ev_reopen"> <actions _delta="redefine"> <!-- Because an action has no id, you must redefine ALL actions for that transition --> <action> <!-- Execute on current object the method with id="IncrementCounter" --> <verb>IncrementCounter</verb> <!-- with the following parameters --> <params> <!-- attribute code of the counter to increment --> <param xsi:type="attcode">reopen_count</param> <!-- also the default value is set in PHP, it must be done again in XML --> <param xsi:type="int">1</param> </params> </action> </actions> </transition> </transitions> </state>
在演示文稿中添加计数器
让我们在UserRequest详细信息页面的第3列和SLA报告字段集中添加此reopen_计数。
为了能够编写此类增量XML,您需要确定
在详细信息的哪个列中显示该字段:上校:col1 col:col2 col:col3(如果定义了列)。
检索字段集代码(如果已定义)
猜测一个等级,该等级用于将特定字段定位在另一个字段之前或之后。在默认数据模型中,等级在公共容器内的字段之间有10的增量:字段集,列或页面(?)。
要获取当前的XML演示文稿,请检查已安装的iTop服务器,文件itop/data/datamodel-production.xml,其中包含iTop的已编译XML。
<class id="UserRequest" _delta="must_exist"> <presentation> <details> <items> <item id="col:col3"> <items> <item id="fieldset:Ticket:SLA"> <items> <item id="reopen_count" _delta="define"> <rank>80</rank> </item> </items> </item> </items> </item> </items> </details> </presentation> </class> 添加柜台标签
[ ttps://]itop_design / dictionaries / dictionary@EN US / entries <entry id="Class:UserRequest/Attribute:reopen_count" _delta="define">Reopening counter</entry>
该方法是通用的,因此可以用于其他计数器
如果您在类工单而不是UserRequest上声明了它,那么它也可以在任何变更类上使用