Conditional showing of Dynamic fields

Moderator: crythias

Post Reply
retro2707
Znuny advanced
Posts: 131
Joined: 16 Apr 2014, 17:06
Znuny Version: 6.0.12

Conditional showing of Dynamic fields

Post by retro2707 »

Hi,

I want to be able to show a dynamic field on a process ticket on the customer web portal if a specific value in a dropdown list is called e.g.

If DynamicField_DropdownBox1 = 1 Then
DynamicField_ExtraBox = Visable

If DynamicField_DropdownBox1 <> 1 Then
DynamicField_ExtraBox = Hidden

I have OTRS and KIX4OTRS installed at their latest version.

I found this code below but to be honest I dont know where to begin. I dont even know how to modify it or even where on my RedHat system to put the code (sorry im a bit of a newbie!).

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>

Could anyone point me in the right direction please? I know its available as a feature addon but I dont have a support contract with OTRS so that is not an option. KIX4OTRS does Dynamic field Dependencies but only for showing specific items within a list. Not the actual visibility of the Dynamic field itself
Setup:
OTRS 6.0.12
Hosted on CentOS 7.4/ MySQL - MariaDB (5.5.60)
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Conditional showing of Dynamic fields

Post by RStraub »

Hey retro,

we're working with that code as well, though a bit modified. We're using it for the Agent side though. Please carefully read this and the two linked threads:
viewtopic.php?f=60&t=24116

First, locate the file where you want to make the changes. That would probably be the "CustomerTicketMessage.dtl".

Then the nonetext function (e.g. top of the file), which you are calling, to hide all fields as default (here it's called nofields):

Code: Select all

<script type="text/javascript">//<![CDATA[

function nofields () {
        $('#DynamicField_ProcessManagementProcessID').parent().addClass( 'Hidden' );
//      $('#DynamicField_ProcessManagementProcessID').parent().removeClass( 'Hidden' );
        $('#LabelDynamicField_ProcessManagementProcessID').parent().addClass( 'Hidden' );
//      $('#LabelDynamicField_ProcessManagementProcessID').parent().removeClass( 'Hidden' );
        $('#DynamicField_ProcessManagementActivityID').parent().addClass( 'Hidden' );
//      $('#DynamicField_ProcessManagementActivityID').parent().removeClass( 'Hidden' );
        $('#LabelDynamicField_ProcessManagementActivityID').parent().addClass( 'Hidden' );
//      $('#LabelDynamicField_ProcessManagementActivityID').parent().removeClass( 'Hidden' );
}

//]]></script>
Then you have to add the function to the called functions on page load:

Code: Select all

<!--dtl:js_on_document_complete-->
<script type="text/javascript">//<![CDATA[
    Core.Agent.TicketAction.Init();
    Core.Config.Set('Localization.Delete', "$JSText{"Delete"}");
    nofields(); // Customization
# ---
# ITSM
# ---
    $('a.AsPopup').bind('click', function (Event) { Core.UI.Popup.OpenPopup($(this).attr('href'), 'Action'); return false;});
# ---
//]]></script>
<!--dtl:js_on_document_complete-->
and only then you can start with the case-switch right after a field selection.

(Note: As you want to have dependencies on dynamic fields, you'll need to 'hardcode' that field into the dtl. See the commented block "example of how to use fixed dynamic field blocks for customizations" as they are found in the Agent-files)

I hope this helps you :)

Best regards,
Rolf
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
retro2707
Znuny advanced
Posts: 131
Joined: 16 Apr 2014, 17:06
Znuny Version: 6.0.12

Re: Conditional showing of Dynamic fields

Post by retro2707 »

Hi,

Thanks for the reply. I have managed to get it working with the example of the Junk queue showing/ hiding a dynamicfield in the new ticket form on the customer portal.

The problem is that a process ticket seems to use "CustomerTicketProcess" not "CustomerTicketMessage" I did a search for appropriate files and in ./Kernel/Output/HTML/Standard/CustomerTicketProcess.dtl there didnt seem to be anything like the same format as the CustomerTicketMessage.dtl.

Any pointers on how to get this working with a process ticket?

Im learning things slowly!

Retro
Setup:
OTRS 6.0.12
Hosted on CentOS 7.4/ MySQL - MariaDB (5.5.60)
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Re: Conditional showing of Dynamic fields

Post by aph »

You could place your script at the bottom of the CustomerTicketProcess.dtl before the last <!--dtl:js_on_document_complete--> statement
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
retro2707
Znuny advanced
Posts: 131
Joined: 16 Apr 2014, 17:06
Znuny Version: 6.0.12

Re: Conditional showing of Dynamic fields

Post by retro2707 »

Thanks for the reply. Unfortunately that doesent seem to work. As a test I added the Queue option to the process activity and just put the block of code in:

Code: Select all

<!-- dtl:block:Queue -->
                <div>
                    <label for="Dest" class="Mandatory">
                        <span class="Marker">*</span>
                        $Text{"To Infinity and Beyond!"}:
                    </label>
                    $Data{"ToStrg"}
                    <div id="DestError" class="TooltipErrorMessage" ><p>$Text{"This field is required."}</p></div>
                    <div id="DestServerError" class="TooltipErrorMessage NoJavaScriptMessage$QData{"QueueInvalid"}" ><p>$Text{"This field is required."}</p></div>
                    <div class="Clear"></div>
                </div>
<!-- dtl:block:Queue -->
If it was recognising the code block the text would change to "To infinity and Beyond!". That does not happen. (it works fine when I do it with a regular customer ticket). I think the fact that you initially select a dropdown of your process tickets THEN choose your fields on a new form is throwing things off somehow.

Could anyone provide some insight on how I could modify "standard" and dynamic fields from within a process ticket form using either a .dtl file or another method?

Thanks,

Retro
Setup:
OTRS 6.0.12
Hosted on CentOS 7.4/ MySQL - MariaDB (5.5.60)
retro2707
Znuny advanced
Posts: 131
Joined: 16 Apr 2014, 17:06
Znuny Version: 6.0.12

Re: Conditional showing of Dynamic fields

Post by retro2707 »

Any ideas? I thought this would be a fairly common request.

Im being pushed to build these processes and if possible wanted to get a definitive on this before i went through and set them all up one way or another.

Cheers,

Brendan
Setup:
OTRS 6.0.12
Hosted on CentOS 7.4/ MySQL - MariaDB (5.5.60)
retro2707
Znuny advanced
Posts: 131
Joined: 16 Apr 2014, 17:06
Znuny Version: 6.0.12

Re: Conditional showing of Dynamic fields

Post by retro2707 »

Are there no .dtl editing superstars that can come to my aid on this one? I would be extremely grateful!
Setup:
OTRS 6.0.12
Hosted on CentOS 7.4/ MySQL - MariaDB (5.5.60)
tto
Znuny wizard
Posts: 315
Joined: 09 Jan 2007, 15:24
Znuny Version: OTRS 5.0.x
Real Name: Torsten
Company: c.a.p.e. IT GmbH
Location: Chemnitz
Contact:

Re: Conditional showing of Dynamic fields

Post by tto »

retro2707 wrote:Are there no .dtl editing superstars that can come to my aid on this one? I would be extremely grateful!

If you're useing KIX4OTRS there's no need to modify any files in order to dis-/enable dynamic fields depending on selected queue, service, ticket type, or priority. Go to SysConfig and check out Ticket::Frontend::DynamicField###DisabledDynamicFields. There you may define some sort of rules which hide/show or dis-/enable dynamic fields for input. The configuration should look like this:

Code: Select all

Key::= <ActionNameRegExp>:::<Service|Queue|Type|State|Priority>:::<ValueToMatch> 
ValueToMatch ::= <[regexp]SomeRegExp.* / SomeString / EMPTY
Value::= <regexp for fields to disable if rule matches>
Some examples probably help most:

Code: Select all

(.+):::Service:::EMPTY" => (TicketFreeText13|TicketFreeText14|FirstContactTimestamp)
This disables DF TicketFreeText13 /..14 of FirstContactTimeStamp if no service is yet selected

Code: Select all

"(.+):::Queue:::[regexp]^(?:(?!(^NOC.*)).)*$" => (Anmeldung|Abmeldung)
This disables DF "Anmeldung" and "Abmeldung" if the selected queue is NOT named like "*NOC*". The weird regexp is just used to get a "NOT LIKE"... :-)

Code: Select all

"(.+):::Queue:::[regexp]^NOC.*" => (CustomerDesireDate)
This disables DF "CustomerDesireDate" if a NOC-Queue is selected.


regards, T.
--
KIX 17.x (fork of OTRS)
Professional KIX-, or OTRS-integration, development and consulting by c.a.p.e. IT - http://www.cape-it.de
For questions and hints regarding KIX(4OTRS) please go to https://forum.kixdesk.com/
Bei Fragen und Hinweisen zu KIX(4OTRS) bitte an https://forum.kixdesk.com/ wenden.
retro2707
Znuny advanced
Posts: 131
Joined: 16 Apr 2014, 17:06
Znuny Version: 6.0.12

Re: Conditional showing of Dynamic fields

Post by retro2707 »

Just wanted to say thank you very much tto for this. I will get chance to look at your words of wisdom hopefully before the end of the week.

Much appreciated.

Brendan
Setup:
OTRS 6.0.12
Hosted on CentOS 7.4/ MySQL - MariaDB (5.5.60)
pgold30
Znuny newbie
Posts: 6
Joined: 19 May 2015, 16:55
Znuny Version: 4.0.7
Real Name: Pablo
Company: -

Re: Conditional showing of Dynamic fields

Post by pgold30 »

Hi torsten , i try what u say with otrs 3.3.12 and kix4otrs 6.15 but
:::Queue:::[regexp]^NOC.*" => (Responsibilityticketopen)
but the dynamic field is always showed , neved disabled, i am doing something wrong?
Regards
tto
Znuny wizard
Posts: 315
Joined: 09 Jan 2007, 15:24
Znuny Version: OTRS 5.0.x
Real Name: Torsten
Company: c.a.p.e. IT GmbH
Location: Chemnitz
Contact:

Re: Conditional showing of Dynamic fields

Post by tto »

pgold30 wrote:Hi torsten , i try what u say with otrs 3.3.12 and kix4otrs 6.15 but
:::Queue:::[regexp]^NOC.*" => (Responsibilityticketopen)
but the dynamic field is always showed , neved disabled, i am doing something wrong?
Regards
lloks like you missed "(.+)" before ":::Queue:::[regexp]...". Please post a full screenshot of your SysConfig. There's to much doubt about what you really configured.

regards, T.

PS: please NO private messages. Thanx.
--
KIX 17.x (fork of OTRS)
Professional KIX-, or OTRS-integration, development and consulting by c.a.p.e. IT - http://www.cape-it.de
For questions and hints regarding KIX(4OTRS) please go to https://forum.kixdesk.com/
Bei Fragen und Hinweisen zu KIX(4OTRS) bitte an https://forum.kixdesk.com/ wenden.
pgold30
Znuny newbie
Posts: 6
Joined: 19 May 2015, 16:55
Znuny Version: 4.0.7
Real Name: Pablo
Company: -

Re: Conditional showing of Dynamic fields

Post by pgold30 »

added the symbol , but still not working
key : (.+):::Queue:::[regexp]^NOC.*" => (Responsibilityticketopen)
content:Responsibilityticketopen
I atach the print screens
Regards
Screenshot 2015-06-01 at 11.21.32.png
Screenshot 2015-06-01 at 11.20.09.png
You do not have the required permissions to view the files attached to this post.
tto
Znuny wizard
Posts: 315
Joined: 09 Jan 2007, 15:24
Znuny Version: OTRS 5.0.x
Real Name: Torsten
Company: c.a.p.e. IT GmbH
Location: Chemnitz
Contact:

Re: Conditional showing of Dynamic fields

Post by tto »

...please remove following code from key in Ticket::Frontend::DynamicField###DisabledDynamicFields

Code: Select all

" => (Responsibilityticketopen)
btw: "=>" usually separates key from value
--
KIX 17.x (fork of OTRS)
Professional KIX-, or OTRS-integration, development and consulting by c.a.p.e. IT - http://www.cape-it.de
For questions and hints regarding KIX(4OTRS) please go to https://forum.kixdesk.com/
Bei Fragen und Hinweisen zu KIX(4OTRS) bitte an https://forum.kixdesk.com/ wenden.
pgold30
Znuny newbie
Posts: 6
Joined: 19 May 2015, 16:55
Znuny Version: 4.0.7
Real Name: Pablo
Company: -

Re: Conditional showing of Dynamic fields

Post by pgold30 »

Sry im kinda new XD , ok so now its like this
Screenshot 2015-06-01 at 12.17.54.png
but im seeing the dynamic field all the time in new ticket
Screenshot 2015-06-01 at 12.19.40.png
You do not have the required permissions to view the files attached to this post.
pgold30
Znuny newbie
Posts: 6
Joined: 19 May 2015, 16:55
Znuny Version: 4.0.7
Real Name: Pablo
Company: -

Re: Conditional showing of Dynamic fields

Post by pgold30 »

Ok i remove the "" and its working now :) thank you so much !!!

:D :D :D :D :D
aubbiali
Znuny newbie
Posts: 1
Joined: 27 Sep 2018, 12:10
Znuny Version: 4.0.0.0
Real Name: Aurélien UBBIALI

Re: Conditional showing of Dynamic fields

Post by aubbiali »

Hi guys,

I would need to reopen this thread.
I would like to the same kind of stuff, I have tried many different command but not way to get it working.

I would like to display the dynamic fields :
- RND Support
- Warranty

... Only for the queues Service-Desk and its subqueues.

Here what I have tried :

Code: Select all

(.+):::Queue:::[regexp]^(?:(?!(^Service-Desk.*)).)*$
Alternative : We can do a sorting on Role : display only to users with Role = ServiceAdmin
Here what I have tried :

Code: Select all

(.+):::Role:::ServiceAdmin
Thanks for your great help.
Post Reply