I need to create a expiration date field, this field should be read only and would be automatically filled up based on date selected (mostly at the time of creation object). So the filed would be calculated to expire, for example 2 weeks from now (Creation of object). Is it possible to do such a field?
Thanks a lot.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes of course no problem !
But you'll need to create a custom module for that ! If you don't know how, take a look at the dedicated section in the documentation : Customizing iTop [iTop Documentation]
There is already in the default datamodel a field that does almost what you want to do : Ticket.last_update.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thanks for answer, I`ve already found some in documentation that you`ve mentioned, but topic is not clearly describing about fields, what type, or if there should be any relation between them, etc. I tried to overload method as described in topic, but it does not work . I need to create autofilled RO date field, that is calculated based on current time. Could you please correct me what is wrong...
Thank you
<?xml version="1.0" encoding="UTF-8"?><itop_designxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"version="1.0"><classes><classid="TEST"_delta="define"><fields><fieldid="date_start"xsi:type="AttributeDateTime"_delta="define"><sql>date_start</sql><default_value/><is_null_allowed>true</is_null_allowed></field><fieldid="end_date"xsi:type="AttributeString"_delta="define"><sql>end_date</sql><default_value/><is_null_allowed>true</is_null_allowed></field></fields><methods/><presentation><details><items><itemid="col:col1"><rank>10</rank><items><itemid="fieldset:Test"><rank>10</rank><items><itemid="date_start"><rank>10</rank></item><itemid="end_date"><rank>30</rank></item></items></item></items></item></items></details><search><items><itemid="end_date"><rank>10</rank></item></items></search><list><items></items></list></presentation><methods><methodid="OnInsert"_delta="define"><static>false</static><access>public</access><type>Overload-DBObject</type><code><![CDATA[ public function OnInsert(){ parent::OnInsert(); $oStartDate = new DateTime($this->Get('date_start')); $oEndDate = clone $oStartDate; $iDuration = 24*3600*14 ; // 24 hours in seconds, 14 days $oEndDate->modify( '+'.$iDuration.' seconds'); $this->Set('end_date',$oEndDate->Format(AttributeDateTime::GetInternalFormat())); }]]></code></method></methods></class></classes><menus></menus></itop_design>
Last edit: Martin 2021-06-23
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In the XML you've forwarded, you're creating a new class, is this intended ? Weren't your new fields meant to be added on an existing class ?
Note that having _delta="define" on the class node means you're adding the whole node and its subnodes, so no need to add more _delta attributes below (there is one more for example on the classes/class/methods/method node)
Your end_date field is an AttributeString, I don't think this is a good idea : you should persist only typed values, and the conversion to strings should be done only when displaying.
Hi, for some reason the methods didnt work no matter what I`ve tried, so I was thinking that something is missing, but eventually I found out that this line was killing it all the time:
Hi there,
I need to create a expiration date field, this field should be read only and would be automatically filled up based on date selected (mostly at the time of creation object). So the filed would be calculated to expire, for example 2 weeks from now (Creation of object). Is it possible to do such a field?
Thanks a lot.
Hello,
Yes of course no problem !
But you'll need to create a custom module for that ! If you don't know how, take a look at the dedicated section in the documentation : Customizing iTop [iTop Documentation]
There is already in the default datamodel a field that does almost what you want to do : Ticket.last_update.
Hi,
thanks for answer, I`ve already found some in documentation that you`ve mentioned, but topic is not clearly describing about fields, what type, or if there should be any relation between them, etc. I tried to overload method as described in topic, but it does not work . I need to create autofilled RO date field, that is calculated based on current time. Could you please correct me what is wrong...
Thank you
Last edit: Martin 2021-06-23
Hello,
In the XML you've forwarded, you're creating a new class, is this intended ? Weren't your new fields meant to be added on an existing class ?
Note that having
_delta="define"
on the class node means you're adding the whole node and its subnodes, so no need to add more_delta
attributes below (there is one more for example on the classes/class/methods/method node)Your end_date field is an AttributeString, I don't think this is a good idea : you should persist only typed values, and the conversion to strings should be done only when displaying.
Also, there are no definitions to set the fields read only. There is a dedicated tutorial for that specific need : Force a field to be read only [iTop Documentation]
To go on, can you describe precisely the problems you're dealing with ? "it does not work" is a bit vague :D
Hi, for some reason the methods didnt work no matter what I`ve tried, so I was thinking that something is missing, but eventually I found out that this line was killing it all the time:
I already had /methods right after fields and bellow methods were omitted. Now my code fully works and does what I wanted :)
Last edit: Martin 2021-07-01
Ok thanks for your feedback !