[SOLVED] Dynamic fields for queues

Moderator: crythias

Post Reply
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

[SOLVED] Dynamic fields for queues

Post by aph »

Hi all,

I want a dynamic field to be visible only to the IT queue. I created a dynamic field AssetNr, added it to Ticket -> Frontend::Agent::Ticket::ViewPhoneNew and enabled it. The field appears on a new phone ticket form.

I tried following viewtopic.php?f=60&t=24116. However, when I select the queue XYZ the field is still visible. Below is my code

Code: Select all

<!--dtl:js_on_document_complete-->
    <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 "1\|\|IT": // need to slash escape the pipes. Also, need to be in numerical order
                    nonetext();
                    $('#DynamicField_AssetNr').parent().removeClass( 'Hidden' );
                    $('#LabelDynamicField_AssetNr').parent().removeClass( 'Hidden' );
                break;
                default:
                    nonetext();

            }
        });
    //]]></script>
Ideally, I'd like the field to appear only after the queue IT is selected. What am I missing?

Thank you.
Last edited by aph on 30 Jul 2014, 17:49, edited 3 times in total.
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Dynamic fields for queues

Post by reneeb »

Are you sure that the IT-Queue has the id "1"?
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Re: Dynamic fields for queues

Post by aph »

The queue IT is second in the list
Unbenannt_26.PNG
If I change

Code: Select all

case "1\|\|IT":
To

Code: Select all

case "2\|\|IT":
the dynamic field 'Asset Number' (key AssetNr) does not 'disappear' when the queue XYZ is selected.
You do not have the required permissions to view the files attached to this post.
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Dynamic fields for queues

Post by reneeb »

It appears on the second place because the list is sorted alphabetically. When you click on "IT", you'll see something "QueueID=7". You have to use that number after "QueueID=" for your JavaScript.
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Re: Dynamic fields for queues

Post by aph »

Hovering the mouse over 'IT' I see

Code: Select all

....Subaction=Change;QueueID=5
On changing the relevant line the Asset number field remains visible and can be edited

Code: Select all

case "5\|\|IT":
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Dynamic fields for queues

Post by crythias »

aph wrote:On changing the relevant line the Asset number field remains visible and can be edited
This information isn't specific enough.

1) It should be hidden before a queue is chosen. Can you confirm this? If not, the rest is pointless.
2) It should at this point display when IT is chosen.
3) It should hide when another queue is chosen.

If it doesn't do 1 or 3 you didn't put this in a proper location.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
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
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Re: Dynamic fields for queues

Post by aph »

1) The field 'Asset number' is not hidden before a queue is chosen
2) It is displayed when IT is chosen
3) It is displayed when another queue is chosen.

Initiating hide at the bottom (viewtopic.php?p=81988#p81988) throws a javascript error 'nonetext is not defined'

I placed it immediatly after the following code and changed nothing else in the dtl file (sorry for some reason the security settings don't allow me to post the whole dtl file.)

Code: Select all

# example template for customizations, see hidden form at the end of the file
#                    <label>$Text{"Templates"}:</label>
#                    <div class="Field">
#                        <button type="button" onclick="$('#Template1').submit()" value="$Text{"Example Template"}">$Text{"Example Template"}</button>
#                    </div>
#                    <div class="Clear"></div>
<!-- dtl:block:TicketType -->
                    <label class="Mandatory" for="TypeID"><span class="Marker">*</span> $Text{"Type"}:</label>
                    <div class="Field">
                        $Data{"TypeStrg"}
                        <div id="TypeIDError" class="TooltipErrorMessage"><p>$Text{"This field is required."}</p></div>
                        <div id="TypeIDServerError" class="TooltipErrorMessage"><p>$Text{"This field is required."}</p></div>
<!--dtl:js_on_document_complete-->
<script type="text/javascript">//<![CDATA[
    $('#TypeID').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#NewPhoneTicket'), 'AJAXUpdate', 'TypeID', ['Dest', 'NewUserID', 'NewResponsibleID', 'NextStateID', 'PriorityID', 'ServiceID', 'SLAID', 'SignKeyID', 'CryptKeyID', 'To', 'Cc', 'Bcc', 'StandardTemplateID' $Data{"DynamicFieldNamesStrg"}]);
    });
//]]></script>
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Re: Dynamic fields for queues

Post by aph »

I was able to get the dynamic fields to be hidden on a page following viewtopic.php?f=60&t=24116. Below is the code snippet (I placed my code in the block <!-- dtl:block:DynamicField -->)

Code: Select all

<!-- dtl:block:DynamicField -->
                    <div class="Row Row_DynamicField_$QData{"Name"}">
                        $Data{"Label"}
                        <div class="Field">
                            $Data{"Field"}
                        </div>
                        <div class="Clear"></div>
                    </div>
<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($('#NewEmailTicket'), 'AJAXUpdate', 'Dest', ['TypeID', 'NewUserID', 'NewResponsibleID', 'NextStateID', 'PriorityID', 'ServiceID', 'SLAID', 'SignKeyID', 'CryptKeyID', 'To', 'Cc', 'Bcc', 'StandardTemplateID' $Data{"DynamicFieldNamesStrg"}]);
    switch ( $('#Dest').val() ) {
            case "5\|\|IT": // need to slash escape the pipes. Also, need to be in numerical order
                nonetext();
                $('#DynamicField_AssetNr').parent().removeClass( 'Hidden' );
                $('#LabelDynamicField_AssetNr').parent().removeClass( 'Hidden' );
            break;
            default:
                nonetext();

        }
    });
//]]></script>
<!-- dtl:block:DynamicField -->
I also initiated hide at the bottom
However, on selecting the queue 'IT', the 'Asset Number' field stays hidden. What am I missing?
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Re: Dynamic fields for queues

Post by aph »

Any idea why the fields remain hidden?

Thanks
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Dynamic fields for queues

Post by reneeb »

Did you check if there were JavaScript errors? Did you add a debug alert? Add an

Code: Select all

alert( $('#Dest').val() );
*before* the switch.
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Re: Dynamic fields for queues

Post by aph »

No, there are no JavaScript errors. Adding an alert before switch doesn't show any errors either

Code: Select all

<!-- dtl:block:DynamicField -->
    <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($('#NewEmailTicket'), 'AJAXUpdate', 'Dest', ['TypeID', 'NewUserID', 'NewResponsibleID', 'NextStateID', 'PriorityID', 'ServiceID', 'SLAID', 'SignKeyID', 'CryptKeyID', 'To', 'Cc', 'Bcc', 'StandardTemplateID' $Data{"DynamicFieldNamesStrg"}]);
        alert( $('#Dest').val() );
		switch ( $('#Dest').val() ) {
                case "5\|\|IT": // need to slash escape the pipes. Also, need to be in numerical order
                    nonetext();
                    $('#DynamicField_AssetNr').parent().removeClass( 'Hidden' );
                    $('#LabelDynamicField_AssetNr').parent().removeClass( 'Hidden' );
                break;
                default:
                    nonetext();

            }
        });
    //]]></script>
<!-- dtl:block:DynamicField -->
During customization, I have used fixed dynamic field blocks instead of showing all dynamic fields one below the other.

Code: Select all

<!-- dtl:block:DynamicField_AssetNr -->
                    <div class="Row Row_DynamicField_$QData{"Name"}">
                        $Data{"Label"}
                        <div class="Field">
                            $Data{"Field"}
                        </div>
                        <div class="Clear"></div>
                    </div>
<!-- dtl:block:DynamicField_AssetNr -->	
Thnak you.
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Dynamic fields for queues

Post by reneeb »

So, please post you complete .dtl
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Re: Dynamic fields for queues

Post by aph »

I realized that I had forgotten the following line while making changes:

Code: Select all

<!--dtl:js_on_document_complete-->
Now my code looks like this:

Code: Select all

<!-- dtl:block:DynamicField -->
    <!--dtl:js_on_document_complete-->
        <script type="text/javascript">//<![CDATA[
        function queueFields() {
            $("[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 "5\|\|IT": // need to slash escape the pipes. Also, need to be in numerical order
                        queueFields();
                        $('#DynamicField_AssetNr').parent().removeClass( 'Hidden' );
                        $('#LabelDynamicField_AssetNr').parent().removeClass( 'Hidden' );
                    break;
                    default:
                        queueFields();

                }
            });
        //]]></script>
<!-- dtl:block:DynamicField -->
Additionally, I did not initiate hide at the bottom. Thus all fields appear when the page is loaded. Once the queue is selected the 'unnecessary' fields are hidden.
Thanks once again!
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Re: Dynamic fields for queues

Post by aph »

I ran into the same problem when hiding fields for subqueues. The code works fine for main queues ABC and PQR, but the dynamic fields are not hidden when I select the subqueues ABC_Intern and PQR_Intern. Below is my code:

Code: Select all

<!-- dtl:block:DynamicField -->
    <!--dtl:js_on_document_complete-->
        <script type="text/javascript">//<![CDATA[
        function queueFields() {
            $("[id^=DynamicField]").parent().addClass( 'Hidden' );
            $("[id^=LabelDynamicField]").parent().addClass('Hidden');
        }
            $('#Dest').bind('change', function (Event) {
                Core.AJAX.FormUpdate($('#NewEmailTicket'), 'AJAXUpdate', 'Dest', ['TypeID', 'NewUserID', 'NewResponsibleID', 'NextStateID', 'PriorityID', 'ServiceID', 'SLAID', 'SignKeyID', 'CryptKeyID', 'To', 'Cc', 'Bcc', 'StandardTemplateID' $Data{"DynamicFieldNamesStrg"}]);
            switch ( $('#Dest').val() ) {
                    case "5\|\|ABC": // need to slash escape the pipes. Also, need to be in numerical order
                        queueFields();
                        $('#DynamicField_xxxx').parent().removeClass( 'Hidden' );
                        $('#LabelDynamicField_xxxx').parent().removeClass( 'Hidden' );
						$('#DynamicField_xxxx').parent().removeClass( 'Hidden' );
                        $('#LabelDynamicField_xxxx').parent().removeClass( 'Hidden' );
						$('#DynamicField_xxxx').parent().removeClass( 'Hidden' );
                        $('#LabelDynamicField_xxxx').parent().removeClass( 'Hidden' );
						$('#DynamicField_xxxx').parent().removeClass( 'Hidden' );
                        $('#LabelDynamicField_xxxx').parent().removeClass( 'Hidden' );
                    break;
					case "6\|\|PQR": // need to slash escape the pipes. Also, need to be in numerical order
                        queueFields();
                        $('#DynamicField_xxxx').parent().removeClass( 'Hidden' );
                        $('#LabelDynamicField_xxxx').parent().removeClass( 'Hidden' );
                    break;
					case "7\|\|ABC:ABC_Intern": // need to slash escape the pipes. Also, need to be in numerical order
                        queueFields();
                        $('#DynamicField_xxxx').parent().removeClass( 'Hidden' );
                        $('#LabelDynamicField_xxxx').parent().removeClass( 'Hidden' );
						$('#DynamicField_xxxx').parent().removeClass( 'Hidden' );
                        $('#LabelDynamicField_xxxx').parent().removeClass( 'Hidden' );
						$('#DynamicField_xxxx').parent().removeClass( 'Hidden' );
                        $('#LabelDynamicField_xxxx').parent().removeClass( 'Hidden' );
						$('#DynamicField_xxxx').parent().removeClass( 'Hidden' );
                        $('#LabelDynamicField_xxxx').parent().removeClass( 'Hidden' );
                    break;
					case "8\|\|PQR:PQR_Intern": // need to slash escape the pipes. Also, need to be in numerical order
                        queueFields();
                        $('#DynamicField_xxxx').parent().removeClass( 'Hidden' );
                        $('#LabelDynamicField_xxxx').parent().removeClass( 'Hidden' );
                    break;
                    default:
                        queueFields();

                }
            });
        //]]></script>
<!-- dtl:block:DynamicField -->
I tried using both variants:

Code: Select all

ABC:ABC_Intern
and

Code: Select all

ABC_Intern
while defining the queue name. Am I overseeing something in the code? Your help is appreciated.
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Dynamic fields for queues

Post by crythias »

when you inspect element on the drop down list, what are you provided with source code for it?
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
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
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Re: Dynamic fields for queues

Post by aph »

Resolved it, the name was incorrect. ABC::ABC_Intern and NOT ABC:ABC_Intern. Thanks again for the tip about alert! reneeb!
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
ruzzetto

Re: [SOLVED] Dynamic fields for queues

Post by ruzzetto »

is this script work also for freetext box?
Post Reply