I have successfully created a custom module to extent the UserRequest by adding a field of type AttributeDate. I now want to provide a default value (which needs to be a date) to this field.
To start with, I want to provide the current date as the default value, but in the future I would like to be able to read the value from another entity (an SLA.)
How can I achieve this?
Thank you in advance for your time
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Another strange behavior I have noticed is this: if no default value is provided for the attribute I have added, when I am trying to create a new UserRequest from the administrator's UI, the attribute's UI widget displays by default a value like the following:
Jun2014WedAMCESTEJune+0200RJunAMCEST
In the user portal no such thing happens.
NB: the attribute does not allow nulls.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
By experimenting I found that this "weird" default value is present only when is_null_allowed is set to false.
Which means that iTop is trying to provide a default value to obey the "null is NOT allowed" constraint.
While on this subject, by checking the file attributedef.class.inc.php I found that for the AttributeDateTime class (parent of AttributeDate), method IsNullAllowed always returns true. Why is this the case?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
and now when I go through the Data Model Toolkit I get all sorts of warnings like these:
Class AsyncTask
field 'created' in table 'priv_async_task' could NOT be NULL
ALTER TABLE priv_async_task CHANGE createdcreated DATETIME NOT NULL
Class DBProperty
field 'change_date' in table 'priv_db_properties' could NOT be NULL
ALTER TABLE priv_db_properties CHANGE change_datechange_date DATETIME NOT NULL
Class CMDBChange
field 'date' in table 'priv_change' could NOT be NULL
ALTER TABLE priv_change CHANGE datedate DATETIME NOT NULL
Class Event
field 'date' in table 'priv_event' could NOT be NULL
ALTER TABLE priv_event CHANGE datedate DATETIME NOT NULL
The method's implementation has a comment about it, but I want to know if I can safely run the update script.
Anyone?
Last edit: Arampatzis Aggelos 2014-06-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have successfully created a custom module to extent the UserRequest by adding a field of type AttributeDate. I now want to provide a default value (which needs to be a date) to this field.
To start with, I want to provide the current date as the default value, but in the future I would like to be able to read the value from another entity (an SLA.)
How can I achieve this?
Thank you in advance for your time
Trying to answer my own question I added the following in my extension's datamodel file:
This works, but only in the administrator's UI and not in the user portal.
Feedback anyone?
Last edit: Arampatzis Aggelos 2014-06-11
Another strange behavior I have noticed is this: if no default value is provided for the attribute I have added, when I am trying to create a new UserRequest from the administrator's UI, the attribute's UI widget displays by default a value like the following:
Jun2014WedAMCESTEJune+0200RJunAMCEST
In the user portal no such thing happens.
NB: the attribute does not allow nulls.
Looking through the schema for the UserRequest I just saw the following (for the attribute I added):
Columns: date_due: DATE, Default: "Jun2014WedAMCESTEJune+0200RJunAMCEST", Null Allowed
How is this possible? In the extension's module I have explicitly specified that nulls are now allowed:
And where does iTop get the default value you see?
By experimenting I found that this "weird" default value is present only when is_null_allowed is set to false.
Which means that iTop is trying to provide a default value to obey the "null is NOT allowed" constraint.
While on this subject, by checking the file attributedef.class.inc.php I found that for the AttributeDateTime class (parent of AttributeDate), method IsNullAllowed always returns true. Why is this the case?
Ok this is getting stupid. I modifed the definition of method IsNullAllowed in class AttributeDateTime from this:
to this:
and now when I go through the Data Model Toolkit I get all sorts of warnings like these:
Class AsyncTask
field 'created' in table 'priv_async_task' could NOT be NULL
ALTER TABLE
priv_async_task
CHANGEcreated
created
DATETIME NOT NULLClass DBProperty
field 'change_date' in table 'priv_db_properties' could NOT be NULL
ALTER TABLE
priv_db_properties
CHANGEchange_date
change_date
DATETIME NOT NULLClass CMDBChange
field 'date' in table 'priv_change' could NOT be NULL
ALTER TABLE
priv_change
CHANGEdate
date
DATETIME NOT NULLClass Event
field 'date' in table 'priv_event' could NOT be NULL
ALTER TABLE
priv_event
CHANGEdate
date
DATETIME NOT NULLThe method's implementation has a comment about it, but I want to know if I can safely run the update script.
Anyone?
Last edit: Arampatzis Aggelos 2014-06-12