OTRS – Show/Hide Dynamic Fields based on Service

Posted on April 25, 2012

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

Filed Under OTRS | 10 Comments

Leave a Comment

If you would like to make a comment, please fill out the form below.

You must be logged in to post a comment.

© Copyright Jeff's Blog • Powered by Wordpress • Using Detour theme created by Brian Gardner.