OTRS – Show/Hide Dynamic Fields based on Service

OTRS — Jeff Eske on April 25, 2012 at 3:13 pm

PLEASE NOTE:  I’ve changed employers and have moved on to other projects.  I no longer use OTRS, or have access to OTRS, so I won’t really be able to help you beyond what I’ve already posted here. 

Jeff

With OTRS 3.1 and higher, you can create dynamic fields (formerly freetext fields) to allow collection of additional information beyond the defaults.  Normally, these fields show up in every ticket that they’ve been setup to show in.  I wanted to be able to hide the fields and then only show them when a particular Service or Services were chosen.  I’ve listed what I did below.
Files Modified:

/opt/otrs/Kernel/Output/HTML/Standard/AgentTicketEmail.dtl
/opt/otrs/Kernel/Output/HTML/Standard/AgentTicketPhone.dtl

Modifications made:

In AgentTicketPhone.dtl and AgentTicketEmail.dtl, I added some code in the section where it checks if the Service is changed:

[CODE:]
<script type=”text/javascript”>//<![CDATA[
$(‘#ServiceID’).bind(‘change’, function (Event) {
Core.AJAX.FormUpdate($(‘#NewPhoneTicket’), ‘AJAXUpdate’, ‘ServiceID’, [‘TypeID’, ‘Dest’, ‘NewUserID’, ‘NewResponsibleID’, ‘NextStateID’, ‘PriorityID’, ‘SLAID’, ‘SignKeyID’, ‘CryptKeyID’, $Data{“DynamicFieldNamesStrg”}, ‘To’, ‘Cc’, ‘Bcc’]);

############  Added by Jeff ##############
#Core.Agent.InitFocus();
switch ($(‘#ServiceID’).val() ) {
case  “2”:
document.getElementById(‘id name’).style.display = ‘block’;
break;
case  “3”:
document.getElementById(‘id name’).style.display = ‘block’;
break;
default:
document.getElementById(‘id name’).style.display = ‘none’;
}

#########  End – Added by Jeff ###########
});
//]]></script>
[/CODE:]

Then I added the “id name” to the Dynamic Field that I wanted to Show/Hide:

[CODE:]
<!– dtl:block:DynamicField_FieldName –>
<div id=”id name” style=”display:none;” class=”Row Row_DynamicField_$QData{“Name”}”>
$Data{“Label”}
<div>
$Data{“Field”}
</div>
<div></div>
</div>
<!– dtl:block:DynamicField_FieldName –>
[/CODE:]

Now, by default, the dynamic field is hidden. When you choose a Service with the ServiceID or 2 or 3, it automagically appears!

Jeff Eske

10 Comments

  1. this code does not work for me. the dynamic field be not seen with the choose of the service.

    Comment by kiki — May 2, 2012 @ 5:05 pm
  2. kiki,

    Sorry, I seem to have possibly had a typo in my original post. I had a couple extra characters.

    I originally had:
    [CODE:]
    $Data{“DynamicFieldNamesStrg”}, ‘To’, ‘Cc’, ‘Bcc’]);
    });
    ############ Added by Jeff ##############
    [/CODE:]

    And it should have been:
    [CODE:]
    $Data{“DynamicFieldNamesStrg”}, ‘To’, ‘Cc’, ‘Bcc’]);

    ############ Added by Jeff ##############
    [/CODE:]

    Notice the bracket,parentheses, and semicolon are removed right above my comment.

    Jeff

    Comment by jeffeske — May 3, 2012 @ 10:28 am
  3. Hi Jeff,
    I had already noticed these extra characters, but my problem is another:
    When I remove the (style=”display:none;), the dynamic field is not seen equally if not enabled in sysconfig (Frontend :: Agent :: Ticket :: ViewPhoneNew).
    but
    when i enable this in sysconfig, two equals fields appear in my “new ticket phone” and all this even without choosing the appropriate service.
    It does not take account of the service.

    What am I doing wrong? needed to activate the field in sysconfig?

    Thank you in advance

    Comment by kiki — May 5, 2012 @ 4:02 pm
  4. kiki,

    Sorry for the slow response. You will need to activate the field within SysConfig so that it can show. Basically, what the hardcoded changes within the pages are doing are making it show only under certain conditions.

    I’ve also gone back and pasted in a new copy of the dynamic field entry from AgentTicketPhone.dtl. This is directly out of my working page.

    Let me know if this helps.

    Jeff

    Comment by jeffeske — May 10, 2012 @ 2:15 pm
  5. kiki,

    Could you post a copy of your AgentTicketPhone.dtl file for me to look at? Or at least the section where you’ve added the new code?

    Thanks.

    Jeff

    Comment by jeffeske — May 17, 2012 @ 8:55 am
  6. Hi Jeff, do you know if this trick can be done using one DynamicField instead Service?

    Thank you,
    @rofc

    Comment by rofcrofc — May 30, 2012 @ 5:08 pm
  7. rofc,
    I’m not sure. My gut tells me that it should work, but I’ve not tried it. If I get time, I’ll give it a whirl.
    Jeff

    Comment by jeffeske — June 1, 2012 @ 11:33 am
  8. Hi Jeff,
    I apologize for the delay in my response, I was on vacation. Far not been able to improve my situation, I send you the code of AgentTicketPhone.dtl file:

    [CODE:]

    $Text{“Service”}:

    $Data{“ServiceStrg”}
    $Text{“Service invalid.”}

    //


    [/CODE:]

    and

    [CODE:]

    $Data{“Label”}

    $Data{“Field”}


    [/CODE:]

    Thank you in advance.

    Comment by kiki — June 4, 2012 @ 8:11 am
  9. Hi Jeff, I realize that my code is not visible, i will send it again:

    [CODE:]

    //

    [/CODE:]

    Comment by kiki — June 5, 2012 @ 7:56 am
  10. […] is the ability to hardcode the display of specific dynamic fields.  Using this, in addition to setting things up to show/hide the dynamic fields in different situations, allows us to setup the new ticket page in a more customizable manner.  You can actually put the […]

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. | Jeff's Blog