I'm using iTop 2.4 and I'm trying to implement a text field that automatically generate its value based on 2 date fields. For example, when editing a Server CI (https://demo.combodo.com/simple/pages/UI.php?operation=modify&class=Server&id=1&c[menu]=ConfigManagementOverview#), when a user enters the "purchase date" field and "end of warranty" date field, there's a new field called "years of service" which value is automatically calculated by decrementing the year in "purchase date" and "end of warranty" (please refer to below image).
Would be really grateful if someone could point me to a field/extensions that already implements this kind of functionality.
Kind regards,
Ray
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In your particular case, use the ComputeValues() method, force that field to be read-only and don't forget to set dependencies when declaring the new field, so it is recomputed on the fly
👍
1
Last edit: Vincent @ Combodo 2021-02-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to implement the compute automation using datamodel XML (it seems that in datamodels/2.x/itop-request-mgmt/datamodel.itop-request-mgmt.xml, you could use <method id="ComputeValues">).
My sample code at the moment (just testing using random string for now but it's not working (please refer to attached image)) datamodel.xml
I would really appreciate if someone could let me know what's wrong. I will try to force the field as read-only as well after this (perhaps the issue is because I haven't made it read-only)? I will try using <method id="GetAttributeFlags"> and <method id="GetInitialStateAttributeFlags"> for making it read-only
If you save your object, is it saved with "hello word" ?
What happen is that your field "year_of_service" has no dependency on other fields, so also it is computed, it is not refreshed. The refresh mechanism works only if a field on which you depend was modified in the screen, then the computed one is refreshed.
It your goal is just to prefill values, then check the tutorial on prefill forms.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes it will save the attribute with value "hello world" when clicking save. As proposed, I have added some dependency to the field so that the computation is refreshed on value change of the dependency field.
If anyone is interested, please find below the changes to the field datamodel.xml
Hi All,
I hope all of you are safe and well.
I'm using iTop 2.4 and I'm trying to implement a text field that automatically generate its value based on 2 date fields. For example, when editing a Server CI (https://demo.combodo.com/simple/pages/UI.php?operation=modify&class=Server&id=1&c[menu]=ConfigManagementOverview#), when a user enters the "purchase date" field and "end of warranty" date field, there's a new field called "years of service" which value is automatically calculated by decrementing the year in "purchase date" and "end of warranty" (please refer to below image).

Would be really grateful if someone could point me to a field/extensions that already implements this kind of functionality.
Kind regards,
Ray
Hello Ray,
This require to write your own extension, but such computed field is rather simple to do.
Check here for tutorial: https://www.itophub.io/wiki/page?id=2_7_0%3Acustomization%3Acompute-field
In your particular case, use the ComputeValues() method, force that field to be read-only and don't forget to set dependencies when declaring the new field, so it is recomputed on the fly
Last edit: Vincent @ Combodo 2021-02-12
Hi Vincent,
Thank you very much for the help.
I'm trying to implement the compute automation using datamodel XML (it seems that in
datamodels/2.x/itop-request-mgmt/datamodel.itop-request-mgmt.xml
, you could use<method id="ComputeValues">
).My sample code at the moment (just testing using random string for now but it's not working (please refer to attached image))
datamodel.xml
I would really appreciate if someone could let me know what's wrong. I will try to force the field as read-only as well after this (perhaps the issue is because I haven't made it read-only)? I will try using
<method id="GetAttributeFlags">
and<method id="GetInitialStateAttributeFlags">
for making it read-onlyThank you and I really appreciate any help.
Kind regards,
Ray
If you save your object, is it saved with "hello word" ?
What happen is that your field "year_of_service" has no dependency on other fields, so also it is computed, it is not refreshed. The refresh mechanism works only if a field on which you depend was modified in the screen, then the computed one is refreshed.
It your goal is just to prefill values, then check the tutorial on prefill forms.
Hi Vincent,
Thank you very much for the help!
Yes it will save the attribute with value "hello world" when clicking save. As proposed, I have added some dependency to the field so that the computation is refreshed on value change of the dependency field.
If anyone is interested, please find below the changes to the field
datamodel.xml
Good to know this is working now, and thanks to have shared the final code !