Menu

Set a default value in tickets

2024-08-14
2024-09-17
  • vladimyr andres gonzalez ruiz

    Hello
    Any way to place a default value in the form for the organization and caller attributes in tickets?

    Regarding the organization, I see that you first have to select the organization so that it is set by default when a ticket is created. But I want to set an organization by default to speed up time. and once the default value is set, you can also open the list to choose a different option.

    As for the caller, can you use a filter to take the current contact and put it in the caller form?

    Tthank you so much.

     
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2024-08-14

    You could edit the datamodel to set those values by default. But it applies to everyone.

    You can also do some magic with PHP - PrefillCreationForm .

     
    • vladimyr andres gonzalez ruiz

      Which data model do I have to edit to see the changes? I edited the datamodel.tickets.xml like this and it didn't work:

      <field id="org_id" xsi:type="AttributeExternalKey">
      <sql>org_id</sql>
      <target_class>Organization</target_class>
      <is_null_allowed>false</is_null_allowed>
      <on_target_delete>DEL_AUTO</on_target_delete>
      <default_value>1</default_value>
      </field>

      or

      <field id="org_id" xsi:type="AttributeExternalKey">
      <sql>org_id</sql>
      <target_class>Organization</target_class>
      <is_null_allowed>false</is_null_allowed>
      <on_target_delete>DEL_AUTO</on_target_delete>
      <default>
      <value><![CDATA[SELECT Organization WHERE name = 'Organization1']]></value>
      </default>
      </field>

      What would it be like for the current contact?

      Do you have the documentation on how to do the PHP thing? I would appreciate it very much 😁

       
  • Ladislav Kudláček

    Hello,
    I would like to change a default value in the class UserRequest in a field "impact".
    I read the documentation on the site: https://www.itophub.io/wiki/page?id=3_2_0:customization:add-attribute-sample

    I have a 3.1.1 iTOP version...I downloaded sample-add-attribute from the documentation above.(https://www.itophub.io/wiki/media?media=3_2_0:customization:sample-add-attribute.zip).

    I assume this example should work. So I copied it to the "extensions" directory and ran https://itopurl.com/setup. Even with this example, however, it gives me an error:

    Error loading module "sample-add-attribute": /itop_design/classes/class[Server] at line 4: could not be found - Loaded modules: dictionaries:1.0, core:1.0, application:1.0, authentic-cas:3.1. 1, authent-external:3.1.1, authent-local:3.1.1, combodo-backoffice-darkmoon-theme:3.1.1, combodo-cmdbchange-cleaner:1.0.5, combodo-email-synchro:3.7.2, combodo-password-expiration:1.0.1, itop-attachments:3.1.1, itop-backup:3.1.1, itop-config:3.1.1, itop-files-information:3.1.1, itop-portal-base: 3.1.1, itop-portal:3.1.1, itop-profiles-itil:3.1.1, itop-sla-computation:3.1.1, itop-standard-email-synchro:3.4.4, itop-structure:3.1. 1, itop-themes-compat:3.1.1, itop-tickets:3.1.1, itop-welcome-itil:3.1.1, sample-add-attribute:1.0.0

    Is the example relevant and can I use it, or does it only work in old versions of iTOP? This example worked for me in older versions.

    It says the same mistake like in my own extension with this XML definition.

    <?xml version="1.0" encoding="UTF-8"?>
     <itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.1">
       <classes>
         <class id="UserRequest">
           <fields>
             <field id="impact">
               <default_value _delta="redefine">2</default_value>
             </field>
           </fields>
         </class>
       </classes>
    </itop_design>
    

    I used the same header (version="3.1") like in original file (env-production/itop-request-mgmt-itil/datamodel.itop-request-mgmt-itil.xml).

    Thank you

     
  • Vincent @ Combodo

    The error you report is related to a missing dependency "itop-config-mgmt" defined the server class and "sample-add-attribute" modifies in XML the Server class which does not exist (yet)

    When you create an extension modifying XML classes, then in the module.my-extension.php file you must change the "dependencies" array to list the itop standard modules which brings those classes, because they must be loaded before yours.

     
  • Vincent @ Combodo

    You are right, the zip file is not very good, the dependencies are missing...
    I will give it a look to create a new zip version using itop-design version="3.2"
    Thanks for reporting this...

     
  • Ladislav Kudláček

    Okay okay....and in my an extension is it need the dependencies?

            'dependencies' => array(
                    'itop-tickets/2.4.0',
            ),
    

    This dependency can be seen in original file datamodel.itop-request-mgmt-itil.xml for a class UserRequest. My goal is to change a default value in a class "UserRequest", in a field "impact" from "A department" to "A service".

    Thank very much

     

    Last edit: Ladislav Kudláček 2024-09-11
  • Ladislav Kudláček

    So I got to it again and fixed it.

    Datamodel:

    <?xml version="1.0" encoding="UTF-8"?>
    <itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.1">
      <classes>
        <class id="UserRequest">
          <fields>
            <field id="impact" xsi:type="AttributeEnum" _delta="redefine">
              <values>
                <value id="1">
                  <code>1</code>
                </value>
                <value id="2">
                  <code>2</code>
                </value>
                <value id="3">
                  <code>3</code>
                </value>
              </values>
              <sql>impact</sql>
              <default_value>2</default_value> // I changed value 1 to value 2
              <is_null_allowed>false</is_null_allowed>
              <display_style>list</display_style>
          </field>
        </fields>
       </class>
      </classes>
    </itop_design>
    

    Module and dependencies

    //
    // iTop module definition file
    //
    
    SetupWebPage::AddModule(
        __FILE__, // Path to the current file, all other file names are relative to the directory containing this file
        'user-request-default-value/3.1.1',
        array(
            // Identification
            //
            'label' => 'User request default value',
            'category' => 'business',
    
            // Setup
            //
            'dependencies' => array(
                'itop-request-mgmt-itil/3.1.1'
            ),
            'mandatory' => false,
            'visible' => true,
    
            // Components
            //
            'datamodel' => array(
                //'vendor/autoload.php',
                //'model.user-request-default-value.php', // Contains the PHP code generated by the "compilation" of datamodel.user-request-default-value.xml
            ),
            'webservice' => array(
    
            ),
            'data.struct' => array(
                // add your 'structure' definition XML files here,
            ),
            'data.sample' => array(
                // add your sample data XML files here,
            ),
    
            // Documentation
            //
            'doc.manual_setup' => '', // hyperlink to manual setup documentation, if any
            'doc.more_information' => '', // hyperlink to more information, if any 
    
            // Default settings
            //
            'settings' => array(
                // Module specific settings go here, if any
            ),
        )
    );
    

    It could probably be simpler, but this works.

     

    Last edit: Ladislav Kudláček 2024-09-17

Log in to post a comment.