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

Moderator: crythias

Post Reply
timo2k
Znuny newbie
Posts: 41
Joined: 16 Feb 2010, 21:00
Znuny Version: 4.0.16

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

Post by timo2k »

Hello Board,

I got a simple question regarding the How To "How To Show/Hide Dynamic Field for specific Queue"
I wanted to edit the visibility of DynamicFields in AgentTicketEmail.
Version of OTRS is 4.0.5, but the ID's haven't changed.

This was my way to add a dynic fied to AgentTicketEmail:
1) Added Dynamic Field "ExternalTicketNo"
2) Activated it in Ticket::Frontend::AgentTicketEmail###DynamicField as enabled
Dynamic field shows up when creating new Email-Ticket.
3) Edited AgentTicketEmail.tt and inserted the edited code directly at the beginning (right 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 at every Queue.

Do I have to edit it anywhere else?
System: OTRS 4.0.16 | CentOS 7.2 | Apache 2.4.6 | MariaDB 5.5.44 | Perl 5.16.3 | PHP 5.4.16
eandrex
Znuny expert
Posts: 213
Joined: 04 Nov 2012, 23:58
Znuny Version: OTRS 4.x
Real Name: Esteban
Company: NORTON DE COLOMBIA

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

Post by eandrex »

Place your code inside

Code: Select all

[% WRAPPER JSOnDocumentComplete %]
like this:

https://github.com/OTRS/otrs/blob/rel-4 ... il.tt#L640

by the time your code is executed, i think your select with id "Dest" is not yet loaded, so jquery cant attach any events to it.

and to be in the safe safe, wrap your javascript code inside

Code: Select all

Core.App.Ready(function(){
Your code
});
timo2k
Znuny newbie
Posts: 41
Joined: 16 Feb 2010, 21:00
Znuny Version: 4.0.16

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

Post by timo2k »

I did so, but nothing is happening.
In fact, it removes the menubar...
System: OTRS 4.0.16 | CentOS 7.2 | Apache 2.4.6 | MariaDB 5.5.44 | Perl 5.16.3 | PHP 5.4.16
timo2k
Znuny newbie
Posts: 41
Joined: 16 Feb 2010, 21:00
Znuny Version: 4.0.16

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

Post by timo2k »

Continue of this thread in Howto-section:
reneeb wrote:@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)
I did so, but in fact there are no more Dynamic Fields showing up when I select the queue. I also tried to escape the pipes, but that had no impact.
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
Znuny newbie
Posts: 6
Joined: 20 Nov 2013, 17:49
Znuny Version: 4.0.3

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

Post by ruthconde »

Hi timo2k,
after read the reneeb hint, I have modified my code to this, and works without call external resources.

Code: Select all

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

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

$('#Dest').bind('change', function (Event) {


   switch($('#Dest').val())
   {
        case "50||Queue Name 1":
        case "36||Queue Name 2":
            nonetext();
            $('#DynamicField_Field1').parent().show();
            $('#LabelDynamicField_Field1').parent().show();
        break;
        
        case "57||Queue Name 3":
        case "58||Queue Name 4":
            nonetext();
            $('#DynamicField_Field2').parent().show();
            $('#LabelDynamicField_Field2').parent().show();
         break;
         
         default:
              nonetext();
   }
});

nonetext();
//]]></script>
[% END %]

I would like to hide/show dynamic fields in other views as Note (/opt/otrs/Kernel/Output/HTML/Standard/AgentTicketActionCommon.tt). Any help would be appreciated.
Otrs 4.0.x on Ubuntu Server, Apache2/Mysql 5+
Post Reply