I created a method that will autofill a field with the sum of 2 fields. How will I trigger the function inside the field and how will I pass the value of the 2 fields to the function? Here is the snippet of my code:
<class id="UserRequest"> <fields> <field id="var1" xsi:type="AttributeInteger" _delta="define"> <sql>va1</sql> <default_value> <is_null_allowed>false</is_null_allowed> </default_value></field> <field id="var2" xsi:type="AttributeInteger" _delta="define"> <sql>var2</sql> <default_value> <is_null_allowed>false</is_null_allowed> </default_value></field> <field id="total" xsi:type="AttributeInteger" _delta="define"> <sql>total</sql> <default_value> <is_null_allowed>false</is_null_allowed> </default_value></field> </fields> <methods> <method id="SumNumber" _delta="define"> <static>false</static> <access>public</access> <![CDATA public function SumNumber($v1, $v2) { $total = $v1 + $v2; return $total; } ]> </ code> </method> </methods></class>
<![CDATA public function SumNumber($v1, $v2) { $total = $v1 + $v2; return $total; } ]> </ code>
You'd need to hook in some methods. I would personally use AfterInsert() and AfterUpdate(); and then call the SumNumber() function.
Hello, This tutorial should give you many hints : Calculated field & Cascading update [iTop Documentation]
Log in to post a comment.
I created a method that will autofill a field with the sum of 2 fields. How will I trigger the function inside the field and how will I pass the value of the 2 fields to the function? Here is the snippet of my code:
<class id="UserRequest">
<fields>
<field id="var1" xsi:type="AttributeInteger" _delta="define">
<sql>va1</sql>
<default_value>
<is_null_allowed>false</is_null_allowed>
</default_value></field>
<field id="var2" xsi:type="AttributeInteger" _delta="define">
<sql>var2</sql>
<default_value>
<is_null_allowed>false</is_null_allowed>
</default_value></field>
<field id="total" xsi:type="AttributeInteger" _delta="define">
<sql>total</sql>
<default_value>
<is_null_allowed>false</is_null_allowed>
</default_value></field>
</fields>
<methods>
<method id="SumNumber" _delta="define">
<static>false</static>
<access>public</access>
</method><![CDATA
public function SumNumber($v1, $v2)
{
$total = $v1 + $v2;
return $total;
}
]>
</ code>
</methods></class>You'd need to hook in some methods. I would personally use AfterInsert() and AfterUpdate(); and then call the SumNumber() function.
Hello,
This tutorial should give you many hints : Calculated field & Cascading update [iTop Documentation]