How To Show/Hide Dynamic Field for specific Queue

Dont create your support topics here! No new topics with questions allowed!

Moderator: crythias

User avatar
crythias
Moderator
Posts: 9920
Joined: 04 May 2010, 18:38
OTRS Version?: 4.0.x
Location: SouthWest Florida, USA
Contact:

How To Show/Hide Dynamic Field for specific Queue

Postby crythias » 23 Feb 2014, 18:45

For versions 3.2+

Code: Select all

<script type="text/javascript">//<![CDATA[
function nonetext() {
    $("[id^=DynamicField]").parent().addClass( 'Hidden' );
    $("[id^=LabelDynamicField]").parent().addClass('Hidden');
}
    $('#Dest').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#NewPhoneTicket'), 'AJAXUpdate', 'Dest', ['TypeID', 'NewUserID', 'NewResponsibleID', 'NextStateID', 'PriorityID', 'ServiceID', 'SLAID', 'SignKeyID', 'CryptKeyID', 'To', 'Cc', 'Bcc', 'StandardTemplateID' $Data{"DynamicFieldNamesStrg"}]);
    switch ( $('#Dest').val() ) {
            case "3\|\|Junk": // need to slash escape the pipes. Also, need to be in numerical order
                nonetext();
                $('#DynamicField_myField').parent().removeClass( 'Hidden' );
                $('#LabelDynamicField_myField').parent().removeClass( 'Hidden' );
            break;
            default:
                nonetext();

        }
    });
//]]></script>


viewtopic.php?f=60&t=8032&start=50#p81988
Thanks to reneeb viewtopic.php?f=60&t=8032&start=50#p82769
and Giulio Soleni.
OTRS 4.0.x (private/testing/public) on Linux with MySQL database. Also on github.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask

Giulio Soleni
OTRS superhero
Posts: 389
Joined: 30 Dec 2010, 14:35
OTRS Version?: 5.0.x and 4.0.x
Real Name: Giulio Soleni
Company: IKS srl

Re: How To Show/Hide Dynamic Field for specific Queue

Postby Giulio Soleni » 25 Feb 2014, 17:46

You're welcome crythias :)
...from a first check I would like to add that the same solution works on OTRS 3.3.x versions as well.
OTRS 5.0.x on CentOS 6.9 with MySQL 5.6 database connected to an Active Directory for Agents and Customers.
ITSM and FAQ modules installed.

Giulio Soleni
OTRS superhero
Posts: 389
Joined: 30 Dec 2010, 14:35
OTRS Version?: 5.0.x and 4.0.x
Real Name: Giulio Soleni
Company: IKS srl

Re: How To Show/Hide Dynamic Field for specific Queue

Postby Giulio Soleni » 29 Nov 2014, 14:21

I noticed that the DynamicFields of some specific types (e.g. Date or Date Time) are specified with multiple id's inside the web page;
If you define for example a DateTime dyn field named "myDateTime" you will see every single part of it specified with a distinct id inside the web page:
DynamicField_myDateTimeUsed ... used to make reference at the checkbox to select or not the dyn-field
DynamicField_myDateTimeMinute, DynamicField_myDateTimeHour, DynamicField_myDateTimeMonth, DynamicField_myDateTimeDay, DynamicField_myDateTimeYear for all the part of the dyn field.

Therefore you cannot simply make reference to it with:
$('#DynamicField_myDateTime')
beacause there will be no id actually related to 'DynamicField_myDateTime'

For this reason I think that an improvement of crythias code here above should be:

Code: Select all

<script type="text/javascript">//<![CDATA[
function nonetext() {
    $("[id^=DynamicField]").parent().addClass( 'Hidden' );
    $("[id^=LabelDynamicField]").parent().addClass('Hidden');
}
    $('#Dest').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#NewPhoneTicket'), 'AJAXUpdate', 'Dest', ['TypeID', 'NewUserID', 'NewResponsibleID', 'NextStateID', 'PriorityID', 'ServiceID', 'SLAID', 'SignKeyID', 'CryptKeyID', 'To', 'Cc', 'Bcc', 'StandardTemplateID' $Data{"DynamicFieldNamesStrg"}]);
    switch ( $('#Dest').val() ) {
            case "3\|\|Junk": // need to slash escape the pipes. Also, need to be in numerical order
                nonetext();
                $("[id^=DynamicField_myField]").parent().removeClass( 'Hidden' );
                $("[id^=DynamicField_myField]").parent().removeClass( 'Hidden' );
            break;
            default:
                nonetext();

        }
    });
//]]></script>


By the way, if you want to reset the selection of a Date or Date Time field named for example "myDateTime" after any possible reload of the web page, the nonetext() function may become:

Code: Select all

function nonetext() {
    $("[id^=DynamicField]").parent().addClass( 'Hidden' );
    $("[id^=LabelDynamicField]").parent().addClass('Hidden');
    document.getElementById('DynamicField_myDateTimeUsed').checked = false;
}

OTRS 5.0.x on CentOS 6.9 with MySQL 5.6 database connected to an Active Directory for Agents and Customers.
ITSM and FAQ modules installed.

ruthconde
OTRS newbie
Posts: 6
Joined: 20 Nov 2013, 17:49
OTRS Version?: 4.0.3

Re: How To Show/Hide Dynamic Field for specific Queue

Postby ruthconde » 20 Jan 2015, 13:25

I had this code working fine in otrs 3.3, but I updated to the lastest version and it stops to work. Any suggestion on how I can fix this code for otrs 4?
Thanks for your help!
Otrs 4.0.x on Ubuntu Server, Apache2/Mysql 5+

ruthconde
OTRS newbie
Posts: 6
Joined: 20 Nov 2013, 17:49
OTRS Version?: 4.0.3

Re: How To Show/Hide Dynamic Field for specific Queue

Postby ruthconde » 20 Jan 2015, 16:43

ruthconde wrote:I had this code working fine in otrs 3.3, but I updated to the lastest version and it stops to work. Any suggestion on how I can fix this code for otrs 4?
Thanks for your help!


Hi I find the solution for Compose, EmailNew and PhoneNew views:

Code: Select all

<script type="text/javascript">

function nonetext() {
        $("#DynamicField_Field1").parent().hide();
        $("#LabelDynamicField_Field1").parent().hide();
   $("#DynamicField_Field2").parent().hide();
        $("#LabelDynamicField_Field2").parent().hide();
    }

$('#Dest').change(function(){
   selection = $(this).val();   
   switch(selection)
   {
      case "50||queue name":
     case "36||queue 2 name":
     case "43||queue 3 name":
          nonetext();
           $('#DynamicField_Field1').parent().show();
           $('#LabelDynamicField_Field1').parent().show();
     break;
   
   case "57||queue 4 name":
   case "58||queue 5 name":
         nonetext();
        $('#DynamicField_Field2').parent().show();
        $('#LabelDynamicField_Field2').parent().show();
    break;
   
   default:
           nonetext();
         
           
   }
});

nonetext();
</script>


However, I'm still stacked on how to implement this in AgentTicketActionCommon.tt for other views. Any help would be appreciated.
Otrs 4.0.x on Ubuntu Server, Apache2/Mysql 5+

timo2k
OTRS newbie
Posts: 39
Joined: 16 Feb 2010, 21:00
OTRS Version?: 4.0.16

Re: How To Show/Hide Dynamic Field for specific Queue

Postby timo2k » 30 Jan 2015, 15:51

This was my way to use it in AgentTicketEmail:
1) Added Dynamic Field "ExternalTicketNo"
2) Activated it in Ticket::Frontend::AgentTicketEmail###DynamicField as enabled
Dynamic field is shown
3) Edited AgentTicketEmail.tt and inserted it directly at the beginning after the Copyright/Disclaimer:

Code: Select all

<script type="text/javascript">

function nonetext() {
        $("#DynamicField_ExternalTicketNo").parent().hide();
        $("#LabelDynamicField_ExternalTicketNo").parent().hide();
    }

$('#Dest').change(function(){
   selection = $(this).val();   
   switch(selection)
   {
      case "38||1) IT Support::TestDynamicField":
          nonetext();
           $('#DynamicField_ExternalTicketNo').parent().show();
           $('#LabelDynamicField_ExternalTicketNo').parent().show();
     break;
 
   default:
           nonetext();       
   }
});
nonetext();
</script>

Queue 1) IT Support::TestDynamicField was created for this Test
4) Cleared Template-Cache.

The Dynamic Field still shows up in every Queue.

Do I have to edit it anywhere else?

btw. I'm using 4.0.5, but the CSS-Classes are the same.
System: OTRS 4.0.16 | CentOS 7.2 | Apache 2.4.6 | MariaDB 5.5.44 | Perl 5.16.3 | PHP 5.4.16

ruthconde
OTRS newbie
Posts: 6
Joined: 20 Nov 2013, 17:49
OTRS Version?: 4.0.3

Re: How To Show/Hide Dynamic Field for specific Queue

Postby ruthconde » 02 Feb 2015, 10:05

timo2k wrote:
The Dynamic Field still shows up in every Queue.

Do I have to edit it anywhere else?

btw. I'm using 4.0.5, but the CSS-Classes are the same.


Try to include the jquery script above the script:
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
Otrs 4.0.x on Ubuntu Server, Apache2/Mysql 5+

reneeb
OTRS guru
Posts: 4156
Joined: 13 Mar 2011, 09:54
OTRS Version?: 3.3.x
Company: Perl-Services.de
Contact:

Re: How To Show/Hide Dynamic Field for specific Queue

Postby reneeb » 02 Feb 2015, 10:27

JQuery is shipped with OTRS. No need load an external source...
Perl / OTRS development: http://perl-services.de
Free OTRS add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de

reneeb
OTRS guru
Posts: 4156
Joined: 13 Mar 2011, 09:54
OTRS Version?: 3.3.x
Company: Perl-Services.de
Contact:

Re: How To Show/Hide Dynamic Field for specific Queue

Postby reneeb » 02 Feb 2015, 10:29

@timo2k: Wrap your JS code with JSOnDocumentComplete like lines 58-64 of current AgentTicketEmail.tt (https://github.com/OTRS/otrs/blob/rel-4 ... ail.tt#L58)
Perl / OTRS development: http://perl-services.de
Free OTRS add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de

User avatar
crythias
Moderator
Posts: 9920
Joined: 04 May 2010, 18:38
OTRS Version?: 4.0.x
Location: SouthWest Florida, USA
Contact:

Re: How To Show/Hide Dynamic Field for specific Queue

Postby crythias » 02 Feb 2015, 15:08

Please take the questions to the appropriate forum and let's post the final answer on this topic as this one is moderated, which hinders optimum dialog flow.
OTRS 4.0.x (private/testing/public) on Linux with MySQL database. Also on github.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask

joc8037
OTRS newbie
Posts: 2
Joined: 18 Sep 2015, 16:31
OTRS Version?: 4.0.4

Re: How To Show/Hide Dynamic Field for specific Queue

Postby joc8037 » 18 Sep 2015, 16:33

Works for OTRS 4.x. This does it dynamically rather than having to specify every Dynamic Field explicitly. 'optionx' are the DynamicField names. Map is set up in first few lines of code as 'field_map'. Basing it on Queue instead of TicketType would, of course, use #Dest instead of #TypeID.

Code: Select all

[% WRAPPER JSOnDocumentComplete %]
<script type="text/javascript">

var field_map = {
       '1': ['option1', 'option2'],
       '2': ['option1', 'option2', 'option3', 'option4', 'option5'],
}       


$('#TypeID').change(function() {
       if ($(this).val() in field_map) {
               var enabledFields = field_map[$(this).val()];
       } else {
               var enabledFields = [];
       }
       
       // Find all DynamicField row DIVs
       var dyn_rows = $('div[class*=Row_DynamicField_]');
       dyn_rows.each(function() {
               // Get the full dynamic field class name
               var fieldName = this.className.split(' ').filter(function(v,i,a) {return (v.substring(0,17) == 'Row_DynamicField_');})[0].subst
ring(17);       
               // Show/Hide the field based upon whether the field name is in the list of enabled fields from the map
               if (enabledFields.indexOf(fieldName) >= 0) {
                       $(this).show();
               } else {
                       $(this).hide();
               }
       });
});

$('#TypeID').change();

</script>
[% END %]

joc8037
OTRS newbie
Posts: 2
Joined: 18 Sep 2015, 16:31
OTRS Version?: 4.0.4

Re: How To Show/Hide Dynamic Field for specific Queue

Postby joc8037 » 22 Sep 2015, 20:46

Update - The below coding allows you to have a single file to maintain with just a line of code for your AgentTicketFreeText, AgentTicketEmail, and AgentTicketPhone templates.

Create a file called DynamicTicketType.tt in the template folder:

Code: Select all

    [% WRAPPER JSOnDocumentComplete %]
    <script type="text/javascript">


    // This map defines which dynamic fields should be displayed for each selection of Ticket Type
    //   The format is key: [field1, field2, ...] where 'key' corresponds to the SELECT OPTION value and fieldX corresponds to the dynamic field names
    //
    var field_map = {
           '': ['option2'],
           '1': ['option1', 'option2'],
           '2': ['option1', 'option2', 'option3', 'option4', 'option5', 'option6', 'option7'],
    }


    // Trigger on change of Ticket Type (use '#Dest' to use Queue instead)
    $('#TypeID').change(function() {
           if ($(this).val() in field_map) {
                   var enabledFields = field_map[$(this).val()];
           } else {
                   var enabledFields = [];
           }

           // Find all DynamicField row DIVs
           var dyn_rows = $('div[class*=Row_DynamicField_]');
           dyn_rows.each(function() {
                   // Get the full dynamic field class name
                   var fieldName = this.className.split(' ').filter(function(v,i,a) {return (v.substring(0,17) == 'Row_DynamicField_');})[0].substring(17);

                   if (enabledFields.indexOf(fieldName) >= 0) {
                           $(this).show();
                   } else {
                           $(this).hide();
                   }
           });
    });

    // Simulate an initial change to trigger the dynamic display on page load
    $('#TypeID').change();

    </script>
    [% END %]

Then, include near the top of any template (such as AgentTicketPhone, AgentTicketEmail):

Code: Select all

    [% InsertTemplate("DynamicTicketType.tt") %]


After modifying the DynamicTicketType.tt template, you'll need to clear the cache for the changes to take effect:

sudo /usr/share/otrs/bin/otrs.DeleteCache.pl

spiceweasel
OTRS newbie
Posts: 1
Joined: 14 Oct 2015, 16:09
OTRS Version?: 4.0.13

Re: How To Show/Hide Dynamic Field for specific Queue

Postby spiceweasel » 14 Oct 2015, 16:12

i tried this in my otrs appliance.

but it doesnt work. if i place the code no more dynamic fields are shown.

i usw dynamic article fields. is this the problem?

can you explain how to do this with queues.

and where to place the part

[% InsertTemplate("DynamicTicketType.tt") %]

serwert
OTRS newbie
Posts: 8
Joined: 17 Nov 2014, 14:06
OTRS Version?: 3.1.11
Real Name: Seweryn
Company: Concordia

Re: How To Show/Hide Dynamic Field for specific Queue

Postby serwert » 28 Dec 2015, 16:01

Hi,
I have the same problem with my show/hide dynamic field for specific Queue in OTRS 4

I prepared

Code: Select all

[% WRAPPER JSOnDocumentComplete %]
<script type="text/javascript">//<![CDATA[
$('#TypeID').bind('change', function (Event) {
    Core.AJAX.FormUpdate($('#NewEmailTicket'), 'AJAXUpdate', 'TypeID', [ 'Dest', 'NewUserID', 'NewResponsibleID', 'NextStateID', 'PriorityID', 'ServiceID', 'SLAID', 'SignKeyID', 'CryptKeyID', 'To', 'Cc', 'Bcc', 'StandardTemplateID' [% Data.DynamicFieldNamesStrg %]]);
});
//]]></script>
[% END %]

<script type="text/javascript">

function nonetext() {
        $("#DynamicField_Uznane").parent().hide();
        $("#LabelDynamicField_Uznane").parent().hide();
    }

$('#Dest').change(function(){
   selection = $(this).val(); 
   switch(selection)
   {
      case "159||testowa_kolejka":
          nonetext();
           $('#DynamicField_Uznane').parent().show();
           $('#LabelDynamicField_Uznane').parent().show();
     break;
 
   default:
           nonetext();     
   }
});
nonetext();
</script>

Should I change something else?

dtosun
OTRS newbie
Posts: 24
Joined: 12 Sep 2012, 14:00
OTRS Version?: 4.0.13
Real Name: Dursun Tosun

Re: How To Show/Hide Dynamic Field for specific Queue

Postby dtosun » 01 Mar 2016, 09:28

When i try it, it does not work. Anybody help us to do it?

Solved: I should use key format like this;

Code: Select all

'01||QueueName': ['DynamicFieldName'],

fummek
OTRS newbie
Posts: 29
Joined: 30 Apr 2013, 10:26
OTRS Version?: 3.3.10

Re: How To Show/Hide Dynamic Field for specific Queue

Postby fummek » 25 Apr 2016, 12:12

Doesn't work for me. Any help? Would be great.

## /opt/otrs/Kernel/Output/HTML/Standard/DynamicTicketType.tt

Code: Select all

[% WRAPPER JSOnDocumentComplete %]
 <script type="text/javascript">

  // This map defines which dynamic fields should be displayed for each selection of Ticket Type
  // The format is key: [field1, field2, ...] where 'key' corresponds to the SELECT OPTION value
  // and fieldX corresponds to the dynamic field names
  //

   // _Test: '01||QueueName': ['DynamicFieldName'],

  var field_map = {
           'QueueName1': [DynField_1'],
           'QueueName2': ['DynField_2', 'DynField_3', 'DynField_4'],
    }


  // Trigger on change of Ticket Type (#TypeID)  (use '#Dest' to use Queue instead)
  $('#Dest').change(function() {
         if ($(this).val() in field_map) {
                 var enabledFields = field_map[$(this).val()];
         } else {
                 var enabledFields = [];
         }

         // Find all DynamicField row DIVs
         var dyn_rows = $('div[class*=Row_DynamicField_]');
         dyn_rows.each(function() {
           // Get the full dynamic field class name
           var fieldName = this.className.split(' ').filter(function(v,i,a) {return (v.substring(0,17) == 'Row_DynamicField_');})[0].substring(17);

           if (enabledFields.indexOf(fieldName) >= 0) {
            $(this).show();
           } else {
            $(this).hide();
           }
         });
   });

  // Simulate an initial change to trigger the dynamic display on page load
  $('#Dest').change();

 </script>

[% END %]


## /opt/otrs/Kernel/Output/HTML/Standard/AgentTicketFreeText.tt

Code: Select all

# --
# AgentTicketFreeText.tt - provides HTML form for free text mask
# Copyright (C) 2001-2015 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

[% InsertTemplate("DynamicTicketType.tt") %]

[% InsertTemplate("AgentTicketActionCommon.tt") %]

OTRS Version: 3.3.10 (ITSM, KIX4OTRS, FAQ, MasterSlave, CustomExtensions)
OS: Debian GNU/Linux 7.9 (wheezy)
------------------------
OTRS Version: 4.0.6 (FAQ)
OS: Debian GNU/Linux 7.9 (wheezy)

Giulio Soleni
OTRS superhero
Posts: 389
Joined: 30 Dec 2010, 14:35
OTRS Version?: 5.0.x and 4.0.x
Real Name: Giulio Soleni
Company: IKS srl

Re: How To Show/Hide Dynamic Field for specific Queue

Postby Giulio Soleni » 07 May 2016, 14:54

This is an updated version that I tested for version 5.0.x
To test the model I defined the following items:
- definition of the following 6 queues:
"ACME01::Queue1" ... queue-id: 10
"ACME01::Queue2" ... queue-id: 11
"ACME01::Queue3" ... queue-id: 12
"ACME02::Queue1" ... queue-id: 20
"ACME02::Queue2" ... queue-id: 21
"ACME02::Queue3" ... queue-id: 22

Needless to say the queue-id's and the names of the queues may change for your specific system and that you have to adjust the CustomerTicketMessage.tt file as well.

- definition of three example dynamic fields:
myDropDown01 : as a drop down fileld
myTextField01 : as a free text field
myTextField02 : as a free text field

Again, these are just examples that you may change to suit your needs

All these fields must be defined in SysConfig Ticket -> Frontend::Customer::Ticket::ViewNew under "Ticket::Frontend::CustomerTicketMessage###DynamicField" parameter.
Please mind that ALL of them must be defined with content "1" (that is optional), and NEVER "2" (that is mandatory) because they will be defined as mandatory within the CustomerTicketMessage.tt template file only for some queues.

Then, here is my personalization of the "Queue" block of
/opt/otrs/Custom/Kernel/Output/HTML/Templates/Standard/CustomerTicketMessage.tt
template file.
You should replace all the stuff between the two statements

Code: Select all

[% RenderBlockStart("Queue") %]
...
[% RenderBlockEnd("Queue") %]

with the code specified here below...

Mind not to change the original /opt/otrs/Kernel/Output/HTML/Templates/Standard/CustomerTicketMessage.tt template, but take a copy instead and edit the /opt/otrs/Custom... file for your needs.
Given the specifics above, the logic that rules my example is the following:
A) myDropDown01 is available and mandatory only for ACME01::Queue1
B) myTextField01 is available and mandatory for ACME02::Queue2 and ACME02::Queue3
C) myTextField02 is available and mandatory only for ACME02::Queue3
D) ACME01::Queue1 and ACME02::Queue1 queues have a subject and body already filled out

Code: Select all

[% RenderBlockStart("Queue") %]
                <div>
                    <label for="Dest" class="Mandatory">
                        <span class="Marker">*</span>
                        [% Translate("To") | html %]:
                    </label>
                    [% Data.ToStrg %]
                    <div id="DestError" class="TooltipErrorMessage" ><p>[% Translate("This field is required.") | html %]</p></div>
                    <div id="DestServerError" class="TooltipErrorMessage NoJavaScriptMessage[% Data.QueueInvalid | html %]" ><p>[% Translate("This field is required.") | html %]</p></div>
                    <div class="Clear"></div>
                </div>
[% WRAPPER JSOnDocumentComplete %]
<script type="text/javascript">//<![CDATA[

//// START EDIT
//// myDropDown01 is available and mandatory only for ACME01::Queue1
//// myTextField01 is available and mandatory for ACME02::Queue2 and ACME02::Queue3
//// myTextField02 is available and mandatory only for ACME02::Queue3
//// ACME01::Queue1 and ACME02::Queue1 queues have a subject and body already filled out

$(document).ready(function() {

    function hideDynFields() {
        $("[id^=DynamicField]").parent().hide();
        $("[id^=LabelDynamicField]").parent().hide();
        $("[id^=DynamicField]").removeClass('Validate_Required');
    }
   
    function initText(subValue,bodyValue) {
        var thisSubject = $('#Subject').val();
        var thisRichText = CKEDITOR.instances.RichText.getData() ;
        var sbjLen = thisSubject.length;
        var textLen = thisRichText.length;
        var totLen = sbjLen*1 + textLen*1;
        if (totLen == 0)
        {
            document.compose.Subject.value = subValue;
            CKEDITOR.instances.RichText.setData( bodyValue, function() {this.checkDirty();});
        }
        else
        {
          var r=confirm("Click Ok to keep the data, or Cancel to load the default body and subject");
          if (r==false)
          {
            document.compose.Subject.value = subValue;
            CKEDITOR.instances.RichText.setData( bodyValue, function() {this.checkDirty();});
          }
        }
      hideDynFields();
    }
   
    function selectQueues() {
        switch ($('#Dest').val() ) {
         case  "10||ACME01::Queue1":
          initText('ACME01::Queue1 subject','<B>ACME01::Queue1</B>&nbsp<br/>body...&nbsp<br/>blah...&nbsp<br/>blah...&nbsp<br/>');
          $("[id^=DynamicField_myDropDown01]").parent().show();
          $("[id^=LabelDynamicField_myDropDown01]").parent().show();
          document.getElementById('DynamicField_myDropDown01').className = 'TicketFreeText Validate_Required ServerError';
          break;
       
         case  "20||ACME02::Queue1":
          initText('ACME02::Queue1 subject','<B>ACME02::Queue1</B>&nbsp<br/>body...&nbsp<br/>blah...&nbsp<br/>blah...&nbsp<br/>');
          break;

         case  "21||ACME02::Queue2":
          initText('','');
          $("[id^=DynamicField_myTextField01]").parent().show();
          $("[id^=LabelDynamicField_myTextField01]").parent().show();
          document.getElementById('DynamicField_myTextField01').className = 'TicketFreeText Validate_Required ServerError';
          break;

         case  "22||ACME02::Queue3":
          initText('','');
          $("[id^=DynamicField_myTextField01]").parent().show();
          $("[id^=LabelDynamicField_myTextField01]").parent().show();
          $("[id^=DynamicField_myTextField02]").parent().show();
          $("[id^=LabelDynamicField_myTextField02]").parent().show();
          document.getElementById('DynamicField_myTextField01').className = 'TicketFreeText Validate_Required ServerError';
          document.getElementById('DynamicField_myTextField02').className = 'TicketFreeText Validate_Required ServerError';
          break;
         
         default:
          initText('','');
        } // End switch   
   } // End selectQueues
   
    $('#Dest').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#NewCustomerTicket'), 'AJAXUpdate', 'Dest', ['TypeID', 'PriorityID', 'ServiceID', 'SLAID', [% Data.DynamicFieldNamesStrg %]]);
        selectQueues();
    });

    selectQueues();

}); // End document ready

//// END EDIT

//]]></script>
[% END %]
[% RenderBlockEnd("Queue") %]


After you made all the changes, I suggest to run a /opt/otrs/bin/otrs.SetPermissions.pl (with the parameters according to your Operating system) to be sure that the customized files take the correct permissions and ownership.
Also run a:

Code: Select all

su -c "/opt/otrs/bin/otrs.Console.pl Maint::Config::Rebuild" -s /bin/bash otrs

to rebuild your configuration.

enjoy
OTRS 5.0.x on CentOS 6.9 with MySQL 5.6 database connected to an Active Directory for Agents and Customers.
ITSM and FAQ modules installed.

manofring
OTRS newbie
Posts: 1
Joined: 06 Jul 2015, 18:57
OTRS Version?: 4.0.6
Real Name: SadykovRM
Company: m12systems.ru

Re: How To Show/Hide Dynamic Field for specific Queue

Postby manofring » 17 Aug 2016, 19:22

Hi!
Its code work in Firefox, but not work with Chrome and IE11, its just freeze if select any other queus, queus without pinned dynamic fields, sory for my bad english. Any suggestion on how I can fix this code?

Giulio Soleni
OTRS superhero
Posts: 389
Joined: 30 Dec 2010, 14:35
OTRS Version?: 5.0.x and 4.0.x
Real Name: Giulio Soleni
Company: IKS srl

Re: How To Show/Hide Dynamic Field for specific Queue

Postby Giulio Soleni » 26 Aug 2016, 15:29

hello,
the code should work for IE and Chrome browser too, maybe a plugin or an add-on prevents the correct browsing... I'd suggest to troubleshoot the situation by running your browsers without plugins:

Start IE11 in No Add-ons mode by running the Run command from the Start menu, and then typing

Code: Select all

iexplore.exe -extoff
into the box.

For Chrome you should run the browser with the following parameters:
--disable-extensions
--disable-plugins

You may try some useful information also here and here
OTRS 5.0.x on CentOS 6.9 with MySQL 5.6 database connected to an Active Directory for Agents and Customers.
ITSM and FAQ modules installed.

Spaeleus
OTRS newbie
Posts: 3
Joined: 16 Dec 2015, 23:20
OTRS Version?: 5 free
Real Name: Dario Croci
Company: AREU

Re: How To Show/Hide Dynamic Field for specific Queue

Postby Spaeleus » 30 Aug 2016, 16:13

joc8037 wrote:Update - The below coding allows you to have a single file to maintain with just a line of code for your AgentTicketFreeText, AgentTicketEmail, and AgentTicketPhone templates.

Create a file called DynamicTicketType.tt in the template folder:
...
Then, include near the top of any template (such as AgentTicketPhone, AgentTicketEmail):


Hi. I tried this configuration, and after some difficulties now it works perfectly for customer's interface into OTRS 5. Thanks! :D

But what about having the same behaviour with Agent interfaces? After digging a while into the templates, I found AgentTicketActionCommon.tt that could be involved, but I don't know if it' the righ one, and variables are not the same, using #NewQueueID instead of #Dest

Code: Select all

...
[% RenderBlockStart("Queue") %]
                        <label for="NewQueueID">[% Translate("Queue") | html %]:</label>
                        <div class="Field">
                            [% Data.QueuesStrg %]
                            <div id="NewQueueIDError" class="TooltipErrorMessage" ><p>[% Translate("This field is required.") | html %]</p></div>
                            <div id="NewQueueIDServerError" class="TooltipErrorMessage"><p>[% Translate("This field is required.") | html %]</p></div>
                        </div>
                        <div class="Clear"></div>
[% WRAPPER JSOnDocumentComplete %]
<script type="text/javascript">//<![CDATA[
    $('#NewQueueID').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#Compose'), 'AJAXUpdate', 'NewQueueID', [ 'TypeID', 'ServiceID', 'NewOwnerID', 'NewResponsibleID', 'NewStateID', 'NewPriorityID', 'StandardTemplateID' [% Data.DynamicFieldNamesStrg %] ]);
    });
//]]></script>
[% END %]
[% RenderBlockEnd("Queue") %]
...

So, in my DynamicQueue.tt for Customer interface I used

Code: Select all

...
var field map = {
   '1||Queue01': ['DynamicField01']
   '2||Queue02': ['DynamicField02']
   ...

How can I do the same with Agent interface?
Many thanks in advance for any help!

OTRS-5.0.10-01

brianmark2
OTRS newbie
Posts: 13
Joined: 01 Sep 2014, 05:52
OTRS Version?: 3.3.8
Real Name: Brian
Company: none

Re: How To Show/Hide Dynamic Field for specific Queue

Postby brianmark2 » 04 Oct 2016, 15:04

Giulio Soleni wrote:This is an updated version that I tested for version 5.0.x
To test the model I defined the following items:
- definition of the following 6 queues:
"ACME01::Queue1" ... queue-id: 10
"ACME01::Queue2" ... queue-id: 11
"ACME01::Queue3" ... queue-id: 12
"ACME02::Queue1" ... queue-id: 20
"ACME02::Queue2" ... queue-id: 21
"ACME02::Queue3" ... queue-id: 22

Needless to say the queue-id's and the names of the queues may change for your specific system and that you have to adjust the CustomerTicketMessage.tt file as well.

- definition of three example dynamic fields:
myDropDown01 : as a drop down fileld
myTextField01 : as a free text field
myTextField02 : as a free text field

Again, these are just examples that you may change to suit your needs

All these fields must be defined in SysConfig Ticket -> Frontend::Customer::Ticket::ViewNew under "Ticket::Frontend::CustomerTicketMessage###DynamicField" parameter.
Please mind that ALL of them must be defined with content "1" (that is optional), and NEVER "2" (that is mandatory) because they will be defined as mandatory within the CustomerTicketMessage.tt template file only for some queues.

Then, here is my personalization of the "Queue" block of
/opt/otrs/Custom/Kernel/Output/HTML/Templates/Standard/CustomerTicketMessage.tt
template file.
You should replace all the stuff between the two statements

Code: Select all

[% RenderBlockStart("Queue") %]
...
[% RenderBlockEnd("Queue") %]

with the code specified here below...

Mind not to change the original /opt/otrs/Kernel/Output/HTML/Templates/Standard/CustomerTicketMessage.tt template, but take a copy instead and edit the /opt/otrs/Custom... file for your needs.
Given the specifics above, the logic that rules my example is the following:
A) myDropDown01 is available and mandatory only for ACME01::Queue1
B) myTextField01 is available and mandatory for ACME02::Queue2 and ACME02::Queue3
C) myTextField02 is available and mandatory only for ACME02::Queue3
D) ACME01::Queue1 and ACME02::Queue1 queues have a subject and body already filled out

Code: Select all

[% RenderBlockStart("Queue") %]
                <div>
                    <label for="Dest" class="Mandatory">
                        <span class="Marker">*</span>
                        [% Translate("To") | html %]:
                    </label>
                    [% Data.ToStrg %]
                    <div id="DestError" class="TooltipErrorMessage" ><p>[% Translate("This field is required.") | html %]</p></div>
                    <div id="DestServerError" class="TooltipErrorMessage NoJavaScriptMessage[% Data.QueueInvalid | html %]" ><p>[% Translate("This field is required.") | html %]</p></div>
                    <div class="Clear"></div>
                </div>
[% WRAPPER JSOnDocumentComplete %]
<script type="text/javascript">//<![CDATA[

//// START EDIT
//// myDropDown01 is available and mandatory only for ACME01::Queue1
//// myTextField01 is available and mandatory for ACME02::Queue2 and ACME02::Queue3
//// myTextField02 is available and mandatory only for ACME02::Queue3
//// ACME01::Queue1 and ACME02::Queue1 queues have a subject and body already filled out

$(document).ready(function() {

    function hideDynFields() {
        $("[id^=DynamicField]").parent().hide();
        $("[id^=LabelDynamicField]").parent().hide();
        $("[id^=DynamicField]").removeClass('Validate_Required');
    }
   
    function initText(subValue,bodyValue) {
        var thisSubject = $('#Subject').val();
        var thisRichText = CKEDITOR.instances.RichText.getData() ;
        var sbjLen = thisSubject.length;
        var textLen = thisRichText.length;
        var totLen = sbjLen*1 + textLen*1;
        if (totLen == 0)
        {
            document.compose.Subject.value = subValue;
            CKEDITOR.instances.RichText.setData( bodyValue, function() {this.checkDirty();});
        }
        else
        {
          var r=confirm("Click Ok to keep the data, or Cancel to load the default body and subject");
          if (r==false)
          {
            document.compose.Subject.value = subValue;
            CKEDITOR.instances.RichText.setData( bodyValue, function() {this.checkDirty();});
          }
        }
      hideDynFields();
    }
   
    function selectQueues() {
        switch ($('#Dest').val() ) {
         case  "10||ACME01::Queue1":
          initText('ACME01::Queue1 subject','<B>ACME01::Queue1</B>&nbsp<br/>body...&nbsp<br/>blah...&nbsp<br/>blah...&nbsp<br/>');
          $("[id^=DynamicField_myDropDown01]").parent().show();
          $("[id^=LabelDynamicField_myDropDown01]").parent().show();
          document.getElementById('DynamicField_myDropDown01').className = 'TicketFreeText Validate_Required ServerError';
          break;
       
         case  "20||ACME02::Queue1":
          initText('ACME02::Queue1 subject','<B>ACME02::Queue1</B>&nbsp<br/>body...&nbsp<br/>blah...&nbsp<br/>blah...&nbsp<br/>');
          break;

         case  "21||ACME02::Queue2":
          initText('','');
          $("[id^=DynamicField_myTextField01]").parent().show();
          $("[id^=LabelDynamicField_myTextField01]").parent().show();
          document.getElementById('DynamicField_myTextField01').className = 'TicketFreeText Validate_Required ServerError';
          break;

         case  "22||ACME02::Queue3":
          initText('','');
          $("[id^=DynamicField_myTextField01]").parent().show();
          $("[id^=LabelDynamicField_myTextField01]").parent().show();
          $("[id^=DynamicField_myTextField02]").parent().show();
          $("[id^=LabelDynamicField_myTextField02]").parent().show();
          document.getElementById('DynamicField_myTextField01').className = 'TicketFreeText Validate_Required ServerError';
          document.getElementById('DynamicField_myTextField02').className = 'TicketFreeText Validate_Required ServerError';
          break;
         
         default:
          initText('','');
        } // End switch   
   } // End selectQueues
   
    $('#Dest').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#NewCustomerTicket'), 'AJAXUpdate', 'Dest', ['TypeID', 'PriorityID', 'ServiceID', 'SLAID', [% Data.DynamicFieldNamesStrg %]]);
        selectQueues();
    });

    selectQueues();

}); // End document ready

//// END EDIT

//]]></script>
[% END %]
[% RenderBlockEnd("Queue") %]


After you made all the changes, I suggest to run a /opt/otrs/bin/otrs.SetPermissions.pl (with the parameters according to your Operating system) to be sure that the customized files take the correct permissions and ownership.
Also run a:

Code: Select all

su -c "/opt/otrs/bin/otrs.Console.pl Maint::Config::Rebuild" -s /bin/bash otrs

to rebuild your configuration.

enjoy



Hi Sir,

Newbie here can you please teach me "How To Show/Hide Dynamic Field for specific Queue" step by step. I do not know where to start. How did you come up to this.

Thank you very much.

brianmark2
OTRS newbie
Posts: 13
Joined: 01 Sep 2014, 05:52
OTRS Version?: 3.3.8
Real Name: Brian
Company: none

Re: How To Show/Hide Dynamic Field for specific Queue

Postby brianmark2 » 05 Oct 2016, 13:26

Hi Sir,

How exactly how to show/hide dynamic field for specific Queue? Pls could you show us how to do it step by step.

Thank you very much.

brianmark2
OTRS newbie
Posts: 13
Joined: 01 Sep 2014, 05:52
OTRS Version?: 3.3.8
Real Name: Brian
Company: none

Re: How To Show/Hide Dynamic Field for specific Queue

Postby brianmark2 » 05 Oct 2016, 13:27

Hi Sir,

How exactly how to show/hide dynamic field for specific Queue? Pls could you show us how to do it step by step.

Thank you very much.

brianmark2
OTRS newbie
Posts: 13
Joined: 01 Sep 2014, 05:52
OTRS Version?: 3.3.8
Real Name: Brian
Company: none

Re: How To Show/Hide Dynamic Field for specific Queue

Postby brianmark2 » 05 Oct 2016, 13:42

Hi Ma'am,

Kindly show us how to show or hide dynamic field for specific Queue step by step. I'm confuse and can not follow. I don't know where to start.

I'm using OTRS 5 free.

Pls. need your help.

Thank you very much

allanchalmers
OTRS newbie
Posts: 1
Joined: 01 Dec 2016, 18:53
OTRS Version?: 3.3.11
Real Name: Allan
Company: Aridhia

Re: How To Show/Hide Dynamic Field for specific Queue

Postby allanchalmers » 01 Dec 2016, 19:22

Hi,

I simply want to have a drop down box appear in 'Free Fields' that shows some values.

I have performed the following:

In the screen: "Dynamic Fields List" I have added two Dynamic Fields manually. They appear as links and they are both drop down Types. The object is ''Ticket''.

How do i get these to appear in the free fields of a ticket I have opened in my queue?

I do have admin access to OTRS, however I do not have access to the backend system to be able to run SQL queries / commands.

Please help.

ruzzetto
OTRS wizard
Posts: 121
Joined: 14 Apr 2017, 10:53
OTRS Version?: 5.0.20

Re: How To Show/Hide Dynamic Field for specific Queue

Postby ruzzetto » 12 May 2017, 12:38

when i run

Code: Select all

otrs.Console.pl Maint::Config:Rebuild
it returns me an error:

Error: Could not find Kernel::System::Console::Command::Maint::Config:Rrebuild.

reneeb
OTRS guru
Posts: 4156
Joined: 13 Mar 2011, 09:54
OTRS Version?: 3.3.x
Company: Perl-Services.de
Contact:

Re: How To Show/Hide Dynamic Field for specific Queue

Postby reneeb » 14 May 2017, 08:46

You have on "r" that shouldn't be there: It should be Rebuild, not Rrebuild
Perl / OTRS development: http://perl-services.de
Free OTRS add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de

ruzzetto
OTRS wizard
Posts: 121
Joined: 14 Apr 2017, 10:53
OTRS Version?: 5.0.20

Re: How To Show/Hide Dynamic Field for specific Queue

Postby ruzzetto » 15 May 2017, 10:51

no reeneb it was my fault in typing but with the right command output is the same:

Code: Select all

Error: Could not find Kernel::System::Console::Command::Maint::Config:Rebuild.


[EDIT]: i run the command from the full path e now it works. But i have an issue when i try to open any ticket. When i click on Send the browser returns me this error with a popup:

Code: Select all

Click Ok to keep the data, or Cancel to load the default body and subject

Giulio Soleni
OTRS superhero
Posts: 389
Joined: 30 Dec 2010, 14:35
OTRS Version?: 5.0.x and 4.0.x
Real Name: Giulio Soleni
Company: IKS srl

Re: How To Show/Hide Dynamic Field for specific Queue

Postby Giulio Soleni » 15 May 2017, 16:46

ruzzetto wrote:[EDIT]: i run the command from the full path e now it works. But i have an issue when i try to open any ticket. When i click on Send the browser returns me this error with a popup:

Code: Select all

Click Ok to keep the data, or Cancel to load the default body and subject


That's not an error, it's an alert popup that needs to appear whenever the customer update the web page during the creation of the ticket.
If you do not set such a popup, anytime you change the queue selection or whenever you run an update of the page (e.g. when you attach something to the ticket), every text field you may have already set, is reset to a blank or a default value.
OTRS 5.0.x on CentOS 6.9 with MySQL 5.6 database connected to an Active Directory for Agents and Customers.
ITSM and FAQ modules installed.

ruzzetto
OTRS wizard
Posts: 121
Joined: 14 Apr 2017, 10:53
OTRS Version?: 5.0.20

Re: How To Show/Hide Dynamic Field for specific Queue

Postby ruzzetto » 16 May 2017, 09:30

Giulio probably was a cache issue, indeed after performed a Cache cleanup no issue was present.
Thanks again!

Ebebalf
OTRS newbie
Posts: 43
Joined: 07 May 2015, 13:26
OTRS Version?: 4 Free

Re: How To Show/Hide Dynamic Field for specific Queue

Postby Ebebalf » 31 May 2017, 21:18

Just for understanding: You edit the Template Files and just insert a block of JavaScript?

Wouldn't it be more update-stable, to write the code into a new File and include this seperately, by putting it into Loader::Customer::CommonJS###000-Framework?


Return to “Howtos”

Who is online

Users browsing this forum: No registered users and 2 guests