Menu

Display a dynamic compuded date interval

schirrms
2022-10-26
2022-11-02
  • schirrms

    schirrms - 2022-10-26

    Hello everyboy,

    I'm working on a iTop extension to store SSL certificates informations. The extension itself is fairly simple, as a certificate isn't a very complex CI.
    One of the interresting attribute, of course, is the expiration date. This is easy to store, no problems. But, foa a better reading, I want to add a 'pseudo field' (better not stored in the database) to easely diplay the remaining days before the expiration.
    If I put that in a field in the database, then I have to rely to a daily job to update the field, and that seems "too much"

    On a side point, I think I remember that it is possible to have a field only visible in display mode, but that is completely hidden in edit mode. But my research either give me nothing, or give me broken links on sourceforge...

    Any hints ?

    Thanks,

    Pascal

     
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2022-10-26

    You might want to look into https://www.itophub.io/wiki/page?id=latest%3Acustomization%3Aapi%3Aobjects-manipulation%3Adbobject -> GetAttributeFlags() / GetInitialStateAttributeFlags() .

    But I'm not sure if is possible to have such a field which isn't stored in the DB.

    Alternative approaches:
    - create a custom Attribute Definition (seems overkill)
    - create an extension which hooks into the GUI. I created something like that for my former employer for a completely different use case, but I did not make that code public as it included some more sensitive information (basically I added a third party ref to User Request; and based on the third party org the ticket was created with - our vendors - it added a link to view the ticket on their side in their ticket portals )

     
  • schirrms

    schirrms - 2022-10-27

    Hi Jeffrey & all,

    Thanks for your answer, Jeffrey, it gave me some ideas. Not sure that my ideas will become "Combodo's best practices", though :)

    I finally created a new king of attribrtes, ans associated some php code to update the 'remaining_days' field at each Get (only if a change is detected, of course).

    But I probably miss (at least) one 'Get function', because the update is not lauched when I get the data trough the API interface (or is it an API limitation ? I doubt it, I'm generally much more limited than iTop !)

    Anyway, I still search a way to hide the field in edit mode, I found things, but for external link only ?

    Thanks,

    Pascal

     
  • Vincent @ Combodo

    Hi Pascal,
    There is an undocumented Attribute Type called AttributeDeadline, it's used for displaying when an SLA will expire. It displays its DateTime content as a remaining duration in read mode and a date time in edit mode, pretty much what you want no ?

     
    👍
    1

    Last edit: Vincent @ Combodo 2022-10-28
    • schirrms

      schirrms - 2022-10-28

      Hi Vincent,

      This is indeed a much better way to deal with my situation ! Storing a stable value in the Database, and computing a dynamic value when displayed !

      I'll certainly go in this direction.

      Can I safely use this undocumented attribute, if it suits my needs, or is it safer to 'clone it' ?

      Thanks,

      Pascal

       
  • Vincent @ Combodo

    Just use it, no risk, it should be documented. As I wrote it is used for stopwatch deadlines display.

     
  • schirrms

    schirrms - 2022-11-02

    Hi,

    I finnaly created my own AttributeType, as, for certificate, I didn't need a precision to the minute. Also, instead of storing twice the Certificate expiration date, my new attribute display the expiration date followed by the remaining days.
    Like :
    2032-01-05 ( 3351 jour(s) restant(s) )
    (with the text from the local dictionary, of cource)

    But this was much easier after "taking inspiration" (read : "shaemelessly copied" :)) of your work.

    If you fell adventourous, you can see the work here (Work in progress, caution...) :
    https://github.com/Schirrms/iTop-Certificate
    The link to CI is not started yet.

    Many thanks,

    Pascal

     
    👍
    1

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.