Menu

Custom Class - Generating field content

2018-01-16
2023-02-16
  • Steve Cocks

    Steve Cocks - 2018-01-16

    Hi

    I have 2 classes

    First is called Component. Contains a name and a description field, both Strings

    Second is called ComponentVersion. Contains an ExternalKey to the Component class and a version field, which is a string

    I would like to add a field to the ComponentVersion class which is to be called name and is the name from the Component class concatonated with the version field from the ComponentVersion class with an underscore in between. This field should be read-only in both the database and the user interface as it is calculated when the ComponentVersion is created

    Any idea if this is possible?

    Kind Regards
    Steve

     
  • Vincent @ Combodo

    <naming>
    <attributes>
    <attribute id="user-content-component_name">
    <attribute id="user-content-version">
    </attribute></attribute></attributes>
    </naming>

    Assuming component_name is an externalField defined in the ComponentVersion class
    Combined with a dictionary entry like:

    <entry id="Class:ComponentVersion/Name" _delta="define"><![CDATA[%1$s_%2$s]]></entry>

    https://wiki.openitop.org/doku.php?id=2_4_0:customization:xml_reference
    extract: Define the attributes used to compose the friendly name of an object. By default, the friendly name will be rendered as a concatenation of the given attributes, separated by a white space. You can specify any other format by adding a dictionary entry 'Class:<myclass>/Name'. This format is given as a printf-like formatting expression (Only $s is supported. e.g. '%1$s of %2$s'). As such a format is located in the dictionary, it may be translated, and the friendly name would depend on the language of the end-user. Note that in iTop 2.0.3, a tag <format> was present in the XML files provided with iTop but it was not used, and that was misleading.</format></myclass>

     
    • Rashit A

      Rashit A - 2023-02-16

      Hello.
      Can be explained in more detail.
      Where (in which file) should I add

      <entry id="user-content-Class:ComponentVersion/Name" _delta="define"><![CDATA[%1$s_%2$s]]></entry>

      ??

       
      • Rashit A

        Rashit A - 2023-02-16

        The solution to my question has been found.

         
  • Steve Cocks

    Steve Cocks - 2018-01-16

    awesome thank you so much :)

     
  • Steve Cocks

    Steve Cocks - 2018-02-02

    Hi

    As a follow up

    Everything is working except for the last class which is called componentpackageversion.

    This is a derived from the version class and componentpackage class which is itself derived from the customer and generic componentpackage classes.

    It displays the id and not the concatonated values which i would have expected

    /Steve

     
  • Anilton F. de M. Junior

    Steve Cocks ,

    In OnInsert method you can concat the fields using php code. But, first you need get the value of name field searching in Component where id = [the selected Component] and concat with the version value.

     

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.