Menu

iTop v2.4.0 - Redefine field's enum value

ray
2019-10-22
2019-10-24
  • ray

    ray - 2019-10-22

    Hello,

    I have the following custom field definition:

    <field id="test" xsi:type="AttributeEnum" _delta="define">
               <values>
                          <value>low</value>
                          <value>medium</value>
                          <value>high</value>
               </values>
               <sql>test</sql>
               <default_value/>
               <is_null_allowed>false</is_null_allowed>
               <display_style>list</display_style>
    </field>
    

    I'm attempting to change the enum value and update the entire database with the new enum value:

    <field id="test" xsi:type="AttributeEnum" _delta="define">
               <values>
                          <value id="1">1</value>
                          <value id="2">2</value>
                          <value id="3">3</value>
               </values>
               <sql>test</sql>
               <default_value/>
               <is_null_allowed>false</is_null_allowed>
               <display_style>list</display_style>
    </field>
    

    Is it possible to perform that using the iTop toolkit (I am running iTop v2.4.0)? I tried changing delta to "redefine" but received an error from the toolkit.

    Thank you in advance and I look forward to hearing from you.

     
  • Pierre Goiffon

    Pierre Goiffon - 2019-10-22

    Hello,
    More details please...

    For example :
    Where did you put those pieces of XML ?
    What error are you getting ?

     
  • ray

    ray - 2019-10-22

    Hi Pierre,

    Thank you very much for the reply.

    Setup and objective

    I have created a module called "modify-change-ticket" with dependency of "itop-change-mgmt/2.4.0" (I'm using simple change management instead of the ITIL one). I have installed the empty module using itop/setup and run the toolkit with the following datamodel XML file:

    <?xml version="1.0" encoding="UTF-8"?>
    <itop_design
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
        <classes>
            <class id="Change">
                <fields>
                    <field id="priority" xsi:type="AttributeEnum" _delta="define">
                        <values>
                            <value>low</value>
                            <value>medium</value>
                            <value>high</value>
                        </values>
                        <sql>priority</sql>
                        <default_value/>
                        <is_null_allowed>false</is_null_allowed>
                        <display_style>list</display_style>
                    </field>
                </fields>
                <presentation>
                    <details _delta="redefine">
                        <items>
                            <item id="functionalcis_list">
                                <rank>10</rank>
                            </item>
                            <item id="contacts_list">
                                <rank>20</rank>
                            </item>
                            <item id="workorders_list">
                                <rank>30</rank>
                            </item>
                            <item id="related_request_list">
                                <rank>40</rank>
                            </item>
                            <item id="related_incident_list">
                                <rank>50</rank>
                            </item>
                            <item id="related_problems_list">
                                <rank>60</rank>
                            </item>
                            <item id="child_changes_list">
                                <rank>70</rank>
                            </item>
                            <item id="col:col1">
                                <rank>80</rank>
                                <items>
                                    <item id="fieldset:Ticket:baseinfo">
                                        <rank>10</rank>
                                        <items>
                                            <item id="ref">
                                                <rank>10</rank>
                                            </item>
                                            <item id="org_id">
                                                <rank>20</rank>
                                            </item>
                                            <item id="status">
                                                <rank>30</rank>
                                            </item>
                                            <item id="title">
                                                <rank>40</rank>
                                            </item>
                        <!-- MODIFICATION -->
                                            <item id="priority">
                                                <rank>50</rank>
                                            </item>
                        <!--  -->
                                            <item id="description">
                                                <rank>60</rank>
                                            </item>
                                        </items>
                                    </item>
                                    <item id="fieldset:Ticket:contact">
                                        <rank>20</rank>
                                        <items>
                                            <item id="caller_id">
                                                <rank>10</rank>
                                            </item>
                                            <item id="team_id">
                                                <rank>20</rank>
                                            </item>
                                            <item id="agent_id">
                                                <rank>30</rank>
                                            </item>
                                            <item id="changemanager_id">
                                                <rank>40</rank>
                                            </item>
                                        </items>
                                    </item>
                                </items>
                            </item>
                            <item id="col:col2">
                                <rank>90</rank>
                                <items>
                                    <item id="fieldset:Ticket:resolution">
                                        <rank>10</rank>
                                        <items>
                                            <item id="category">
                                                <rank>10</rank>
                                            </item>
                                            <item id="outage">
                                                <rank>15.1</rank>
                                            </item>
                                            <item id="reject_reason">
                                                <rank>20</rank>
                                            </item>
                                            <item id="fallback_plan">
                                                <rank>30</rank>
                                            </item>
                                        </items>
                                    </item>
                                    <item id="fieldset:Ticket:relation">
                                        <rank>20</rank>
                                        <items>
                                            <item id="parent_id">
                                                <rank>10</rank>
                                            </item>
                                        </items>
                                    </item>
                                </items>
                            </item>
                            <item id="col:col3">
                                <rank>100</rank>
                                <items>
                                    <item id="fieldset:Ticket:date">
                                        <rank>10</rank>
                                        <items>
                                            <item id="creation_date">
                                                <rank>10</rank>
                                            </item>
                                            <item id="start_date">
                                                <rank>20</rank>
                                            </item>
                                            <item id="end_date">
                                                <rank>30</rank>
                                            </item>
                                            <item id="last_update">
                                                <rank>40</rank>
                                            </item>
                                            <item id="approval_date">
                                                <rank>50</rank>
                                            </item>
                                            <item id="close_date">
                                                <rank>60</rank>
                                            </item>
                                        </items>
                                    </item>
                                </items>
                            </item>
                        </items>
                    </details>
                </presentation>
            </class>
        </classes>
    </itop_design>
    

    Application worked perfectly when I create a new change ticket (could display the dropdown list with the specified values ("low", "medium", and "high" )).

    Then, I created 3 sample change tickets with the custom "priority" field set to "low", "medium", and
    "high" to simulate my production iTop v2.4.0 with existing change tickets that have the "priority" field.

    My goal is to change the "priority" field enum value FROM ("low", "medium", and
    "high") TO ("1", "2", "3") which would then allow me to modify the dictionary file to map "1" with "low", "2" with "medium", and "3" with "high" instead of displaying a dropdown list of ("high", "low", "medium" since by default sorted in alphabetical order). This will also make it easier for me to implement a method to automatically compute priority based on risk and impact.

    $aPriorities = array(
                            // low risk
                            1 => array(
                            1 => 1,
                            2 => 2,
                            3 => 3,
                            ),
                            // medium risk
                            2 => array(
                            1 => 2,
                            2 => 2,
                            3 => 3,
                            ),
                            // high risk
                            3 => array(
                            1 => 3,
                            2 => 3,
                            3 => 3,
                            ),
                            );
    

    Problem and error

    1. When changing the "priority" field enum values FROM ("low", "medium", and
      "high") TO ("1", "2", "3") and _delta="define" and there's EXISTING changes with "priority" field enum values ("low", "medium", and "high")
                    <field id="priority" xsi:type="AttributeEnum" _delta="define">
                        <values>
                                 <value id="1">1</value>
                                <value id="2">2</value>
                               <value id="3">3</value>
                        </values>
                        <sql>priority</sql>
                        <default_value/>
                        <is_null_allowed>false</is_null_allowed>
                        <display_style>list</display_style>
                    </field>
    

    ERROR:

    1. When changing the "priority" field enum values FROM ("low", "medium", and
      "high") TO ("1", "2", "3") and _delta="redefine" and there's EXISTING changes with "priority" field enum values ("low", "medium", and "high")
                    <field id="priority" xsi:type="AttributeEnum" _delta="redefine">
                        <values>
                             <value id="1">1</value>
                             <value id="2">2</value>
                             <value id="3">3</value>
                        </values>
                        <sql>priority</sql>
                        <default_value/>
                        <is_null_allowed>false</is_null_allowed>
                        <display_style>list</display_style>
                    </field>
    

    ERROR:

    Error: Error loading module "modify-change-ticket": /itop_design/classes/class[cmdbAbstractObject]/class[Ticket]/class[Change]/fields/field[priority] at line 7: could not be modified (not found) - Loaded modules: dictionaries,core,application,authent-external,authent-ldap,authent-local,itop-attachments,itop-backup,itop-config-mgmt,itop-config,itop-datacenter-mgmt,itop-endusers-devices,itop-portal-base,itop-portal,itop-profiles-itil,itop-sla-computation,itop-storage-mgmt,itop-tickets,itop-virtualization-mgmt,itop-welcome-itil,itop-bridge-virtualization-storage,itop-change-mgmt,itop-incident-mgmt-itil,itop-request-mgmt-itil,itop-service-mgmt,modify-change-ticket
    

    Question

    1. If the toolkit could modify the "priority" field enum values FROM ("low", "medium", and
      "high") TO ("1", "2", "3"); Do they map according to the order mentioned in the <values> tag (i.e. 1->low, 2->medium, 3->high) OR the order as displayed in the dropdown list (refer to below image)
      </values>

    I believe it's following the order as displayed in the dropdown list?

    Thank you and I look forward to hearing from you.

     
    👍
    1
  • ray

    ray - 2019-10-23

    Solved.

    Workaround: use dictionary file to map the value appropriately.
    For example, low->minor, medium->medium, high->major.
    However, I think there's a bug when you want to send email notification since the values are still low, medium, high instead of minor, medium, major.

            'Class:Change/Attribute:priority' => 'Priority',
            'Class:Change/Attribute:priority/Value:low' => 'minor',
            'Class:Change/Attribute:priority/Value:low+' => '',
            'Class:Change/Attribute:priority/Value:medium' => 'medium',
            'Class:Change/Attribute:priority/Value:medium+' => '',
            'Class:Change/Attribute:priority/Value:high' => 'major',
            'Class:Change/Attribute:priority/Value:high+' => '',
    

    Actual fix: need to manually interact with MySQL DB
    https://stackoverflow.com/questions/15642695/mysql-change-a-column-enum-value/15642970

    1. Create union of the old and new enum and apply to the table
    2. Change rows with old enum value to the new one
    3. Remove old enum definition from the table
     
    • Pierre Goiffon

      Pierre Goiffon - 2019-10-24

      Actual fix: need to manually interact with MySQL DB
      https://stackoverflow.com/questions/15642695/mysql-change-a-column-enum-value/15642970
      1. Create union of the old and new enum and apply to the table
      2. Change rows with old enum value to the new one
      3. Remove old enum definition from the table

      Beware that on each setup / toolkit run iTop will update the DB according to its datamodel. So if the old enum values are still in the datamodel, the DB field enum values will be updated and old values added again.

       
  • Pierre Goiffon

    Pierre Goiffon - 2019-10-23

    Hello,
    Many thanks for all these details, really appreciate !

    For a start, you don't need to rewrite so much XML : only specify the nodes you're adding or altering.
    For the presentation, just do something like :

            <class id="Change" _delta="must_exist">
                <presentation>
                    <details>
                        <items>
                            <item id="col:col1">
                                    <item id="fieldset:Ticket:baseinfo">
                                            <item id="priority" _delta="define">
                                                <rank>50</rank>
                                            </item>
                                            <item id="description" _delta="redefine">
                                                <rank>60</rank>
                                            </item>
                                    </item>
                            </item>
                        </items>
                    </details>
                </presentation>
            </class>
    

    About changing enum possible values : both toolkit and setup won't change existing data (the first one just use the same code as the later, by the way). You seems to have MySQL strict mode, so the alter table is failing if existing data uses enum values that are removed.

    You're talking about doing some computation based on enum value, so this is not the answer but the real enum values and displayed labels can be different if you set dictionnary entries.

    So here your only solution is to update in 2 steps :

    • in your custom XML, add new enum value entries, keeping the old ones, run toolkit or setup
    • modify existing value (use bulk edit or export/import)
    • remove old values in your custom XML, run toolkit or setup

    About computation, you can see what is done on the UserRequest class : priority is computed based on impact and urgency values.

     
  • ray

    ray - 2019-10-23

    Thank you very much for the help Pierre :)

     
    • Pierre Goiffon

      Pierre Goiffon - 2019-10-24

      You're welcome :)
      This could become a wiki page, and it might in the future... There will be a massive update of the "customize iTop" page by the end of Q1 2020.

       
      • ray

        ray - 2019-10-24

        Cool, keep up the good work!

         
        ❤️
        1

Log in to post a comment.