[SOLVED] Display FreeText field based on State

Moderator: crythias

Locked
jakezp
Znuny newbie
Posts: 22
Joined: 10 Sep 2011, 09:39
Znuny Version: 3

[SOLVED] Display FreeText field based on State

Post by jakezp »

Hi All,

I am quite new to OTRS setup / configuration and customisation.

I need to know how to disply freetext fields based on the state of the ticket.

Example:
If the state type is 'new' -> display FreeText fields 1 2 3
If the state type is 'open' -> display FreeText fields 4 5
If the state type is 'pending reminder' -> display FreeText fields 67

I don't know if this is possible?

Please advise if this is possible? And if so, how would I go about getting this done.

Thanks,

Jakez
Last edited by jakezp on 21 Sep 2011, 19:08, edited 1 time in total.
Jakez
--------------
OTRS 3.0.9
ITSM 3.0.4
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Display FreeText field based on State

Post by crythias »

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
jakezp
Znuny newbie
Posts: 22
Joined: 10 Sep 2011, 09:39
Znuny Version: 3

Re: Display FreeText field based on State

Post by jakezp »

Thanks for the quick reply crythias,

I have been reading and trying to follow: http://forums.otrs.org/viewtopic.php?f=60&t=8032 for the last couple of days...

I have actually posted a quested in that post as well, but it is subject to approval from admin so it is not showing up yet.

If I can get either one of the 2 ways working viewing / hiding according to view / state it would be awesome.

Could you please assist further?

If you want, I can mail you my original post from topic: http://forums.otrs.org/viewtopic.php?f=60&t=8032

Thanks
Jakez
--------------
OTRS 3.0.9
ITSM 3.0.4
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Display FreeText field based on State

Post by crythias »

Your code is not based upon state, but of queue.
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
jakezp
Znuny newbie
Posts: 22
Joined: 10 Sep 2011, 09:39
Znuny Version: 3

Re: Display FreeText field based on State

Post by jakezp »

Hi again...

I would like to get it work based on state or queue. Either way will work.

Please can you please look at my last post on http://forums.otrs.org/viewtopic.php?f= ... 549#p44549 and help me get it working.

Thanks,
Jakez
--------------
OTRS 3.0.9
ITSM 3.0.4
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Display FreeText field based on State

Post by crythias »

You haven't explained what doesn't work. And you haven't explained where you have put the code. Show me:
in what file you've put the code,
sample location of the code (surrounding before and after a few lines)
what OTRS interface you're using to achieve the desired result,
what happens when you do whatever change
any error messages.
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
jakezp
Znuny newbie
Posts: 22
Joined: 10 Sep 2011, 09:39
Znuny Version: 3

Re: Display FreeText field based on State

Post by jakezp »

As per the post, at the moment, I am not sure which file to put my code in to active it for agents when they create new notes.

So I have the code, which I believe is correct. I just need to know which file to put it in...

When I put it at the bottom of Kernel/Output/HTML/Standard/AgentTicketActionCommon.dtl just before the very last </script>

I get a result of undefined in the Text Editor field and all my FreeText fields are active. I have tested this is QueueA B and C.

If I put it in other files, I get nothing but the original note with all FreeText fields showing...

Other than 'undefine' being displayed in the text field, I get no other errors on screen...

PS. Struggling to connect my my server now, so cannot give specific location in Kernel/Output/HTML/Standard/AgentTicketActionCommon.dtl, but it is the very last <script type="text/javascript"> section...

Ill post directly when I can connect again...
Jakez
--------------
OTRS 3.0.9
ITSM 3.0.4
jakezp
Znuny newbie
Posts: 22
Joined: 10 Sep 2011, 09:39
Znuny Version: 3

Re: Display FreeText field based on State

Post by jakezp »

Hi again...

As promised....

Here is the code I have in /opt/otrs/Kernel/Output/HTML/Standard/AgentTicketActionCommon.dtl

Code: Select all

#Layers
<!--dtl:js_on_document_complete-->
<script type="text/javascript">//<![CDATA[
    Core.Agent.TicketAction.Init();
//above two lines are already there
function nonetext() {
      document.getElementById('TicketFreeText1').style.display = 'none';
      document.getElementById('LabelTicketFreeText1').style.display = 'none';
      document.getElementById('TicketFreeText2').style.display = 'none';
      document.getElementById('LabelTicketFreeText2').style.display = 'none';
      document.getElementById('TicketFreeText3').style.display = 'none';
      document.getElementById('LabelTicketFreeText3').style.display = 'none';
      document.getElementById('TicketFreeText4').style.display = 'none';
      document.getElementById('LabelTicketFreeText4').style.display = 'none';
}
switch ($('#Dest').val() ) { //this is where the queue is relevant (Dest = Queue)
    case  "14\|\|QueueA": 
      document.compose.RichText.value = "This is QueueA"; 
      nonetext();
      document.getElementById('TicketFreeText1').style.display = 'block';
      document.getElementById('LabelTicketFreeText1').style.display = 'block';
      document.getElementById('TicketFreeText2').style.display = 'block';
      document.getElementById('LabelTicketFreeText2').style.display = 'block';
    break;
    case "16\|\|QueueB": 
      document.compose.RichText.value = "QueueB";
      nonetext();
      document.getElementById('TicketFreeText3').style.display = 'block';
      document.getElementById('LabelTicketFreeText3').style.display = 'block';
      document.getElementById('TicketFreeText4').style.display = 'block';
      document.getElementById('LabelTicketFreeText4').style.display = 'block';
    break;
    default:
      document.compose.RichText.value = $('#Dest').val(); 
      nonetext();
}
// the following two lines are the existing last two lines
//]]></script>
<!--dtl:js_on_document_complete-->
Thanks again for assisting...
Jakez
--------------
OTRS 3.0.9
ITSM 3.0.4
jakezp
Znuny newbie
Posts: 22
Joined: 10 Sep 2011, 09:39
Znuny Version: 3

Re: Display FreeText field based on State

Post by jakezp »

Another update....

Ok, im starting to get somewhere, I think...

If I change code as below, the value in the text field change to "Default".

Code: Select all

#Layers
<!--dtl:js_on_document_complete-->
<script type="text/javascript">//<![CDATA[
    Core.Agent.TicketAction.Init();
function nonetext() {
      document.getElementById('TicketFreeText1').style.display = 'none';
      document.getElementById('LabelTicketFreeText1').style.display = 'none';
      document.getElementById('TicketFreeText2').style.display = 'none';
      document.getElementById('LabelTicketFreeText2').style.display = 'none';
}
switch ($('#Dest').val() ) { //this is where the queue is relevant (Dest = Queue)
    case "14\|\|QueueA":
      document.compose.RichText.value = "QueueA";
      nonetext();
      document.getElementById('TicketFreeText1').style.display = 'block';
      document.getElementById('LabelTicketFreeText1').style.display = 'block';
    break;
    case "16\|\|QueueB":
      document.compose.RichText.value = "QueueB";
      nonetext();
      document.getElementById('TicketFreeText2').style.display = 'block';
      document.getElementById('LabelTicketFreeText2').style.display = 'block';
    break;
   default:
      document.compose.RichText.value = "Default";
#      document.compose.RichText.value = $('#Dest').val();
      document.getElementById('TicketFreeText1').style.display = 'none';
      document.getElementById('LabelTicketFreeText1').style.display = 'none';
      document.getElementById('TicketFreeText2').style.display = 'none';
      document.getElementById('LabelTicketFreeText2').style.display = 'none';
}
//]]></script>
<!--dtl:js_on_document_complete-->
So I believe, the 'undefine' message returned previous had to do with the fact that #Dest is undefined?

I then did a search on Kernel/Output/HTML/Standard/CustomerTicketMessage.dtl for '#dest' and found a couple of results. Doing the same on Kernel/Output/HTML/Standard/AgentTicketActionCommon.dtl only shows results for Modified code...

I dont know too much about coding etc, but is this an indication that #Dest is not defined? And if so, how would I fix it?

Is there any code I can add from CustomerTicketMessage.dtl to AgentTicketActionCommon.dtl ?

Thanks...
Jakez
--------------
OTRS 3.0.9
ITSM 3.0.4
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Display FreeText field based on State

Post by crythias »

Just wanted to remind you to look at http://forums.otrs.org/viewtopic.php?f= ... 549#p43215 and although it says AgentTicketPhone, it should likewise apply to AgentTicketEmail. (after Core.AJAX.FormUpdate/Line 77)

You probably should stay out of AgentTicketCommon.dtl. It isn't necessarily relevant (unless you have documentation otherwise).

As for AgentTicketNote ... I have no good answer at this time.
For AgentTicketCompose, it's probably among what I've already said.
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
jakezp
Znuny newbie
Posts: 22
Joined: 10 Sep 2011, 09:39
Znuny Version: 3

Re: Display FreeText field based on State

Post by jakezp »

Hi crythias,

Thanks for the update.

I have been playing around and messing around, etc.

I have got a little more details. And possible ways of doing this. But I would need you to help me as I am not to great with the coding etc..

I have found the following:

The code I have in Kernel/Output/HTML/Standard/AgentTicketActionCommon.dtl works perfectly, except for the fact that Dest is not defined... Hence my error of undefined.

I then went a bit further and messed around a bit more...

I added the following to /Kernel/Output/HTML/Standard/AgentTicketNote.dtl

Code: Select all



<input id="Dest" type="hidden" value="17||QueueA" />
//------ below already in file
$Include{"AgentTicketActionCommon"}
The moment I do this, the FreeTextFields display perfect - hiding the correct one and show the correct one. I then change the entry in /Kernel/Output/HTML/Standard/AgentTicketNote.dtl to 18||QueueB
and once again it hides and displays the fields correctly.

This brings me closer to what I want but still need to get the value to be populated based on the queue the ticket is in.

Any ideas thus far?

I went a step further and looked for data in Kernel/Output/HTML/Standard/AgentTicketActionCommon.dtl that can assist and found the following:

Code: Select all

<!-- dtl:block:HeaderAgentTicketAddtlITSMField -->
# ---

                : $Data{"TicketNumber"} - $QData{"Title","60"}
            </h1>

<!-- dtl:block:TicketBack -->
I then changed this to

Code: Select all

<!-- dtl:block:HeaderAgentTicketAddtlITSMField -->
# ---

                : $Data{"TicketNumber"} - $QData{"Title","60"}
/----- new entry below
                : $Data{"QueueID"}
            </h1>

<!-- dtl:block:TicketBack -->
When I refreshed I got the following at the top of the page:

Add Note to Ticket : 700018 - Ticket - test : 17

instead of

Add Note to Ticket : 700018 - Ticket - test

The 17 being my QueueID as per the database.

So my question, is it at all possible to change this code:

Code: Select all

function nonetext() {
      document.getElementById('TicketFreeText1').style.display = 'none';
      document.getElementById('LabelTicketFreeText1').style.display = 'none';
      document.getElementById('TicketFreeText2').style.display = 'none';
      document.getElementById('LabelTicketFreeText2').style.display = 'none';
}
var $Dest=$Data{"QueueID"};
switch ($('#Dest').val() ) { //this is where the queue is relevant (Dest = Queue)
    case "17\|\|QueueA":
      document.compose.RichText.value = "Q a";
      nonetext();
      document.getElementById('TicketFreeText1').style.display = 'block';
      document.getElementById('LabelTicketFreeText1').style.display = 'block';
    break;
    case "18\|\|QueueB":
      document.compose.RichText.value = "Q b";
      nonetext();
      document.getElementById('TicketFreeText2').style.display = 'block';
      document.getElementById('LabelTicketFreeText2').style.display = 'block';
    break;
   default:
      document.compose.RichText.value = $('#Dest').val();
      document.getElementById('TicketFreeText1').style.display = 'none';
      document.getElementById('LabelTicketFreeText1').style.display = 'none';
      document.getElementById('TicketFreeText2').style.display = 'none';
      document.getElementById('LabelTicketFreeText2').style.display = 'none';
}
To use $Data{"QueueID"} instead of #Dest?

If at all possible, it would be great if you can show me what changes to make to your code...

Thanks,
Jakez
--------------
OTRS 3.0.9
ITSM 3.0.4
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Display FreeText field based on State

Post by crythias »

you can set .value to anything you want, even $Data{"Queue"}

You can even switch on that.

Dest is a construct for the form, but doesn't have anything to do with the *current* value of the Queue

But think about it. If you're switching based upon QueueID, it's a number, so your case should only be numbers.
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
jakezp
Znuny newbie
Posts: 22
Joined: 10 Sep 2011, 09:39
Znuny Version: 3

Re: Display FreeText field based on State

Post by jakezp »

WOOOOOHOOOOO !!!

I got it !!!

I dont know if this is the best way to do it, but it seems to work...

Perhaps you know of a better, more elegant way, but this works for me:

In Kernel/Output/HTML/Standard/AgentTicketNote.dtl, add

Code: Select all

<input id="Dest" type="hidden" value="$Data{"QueueID"}" />
before

Code: Select all

$Include{"AgentTicketActionCommon"}
Then in Kernel/Output/HTML/Standard/AgentTicketActionCommon.dtl, add

Code: Select all


function nonetext() {
      document.getElementById('TicketFreeText1').style.display = 'none';
      document.getElementById('LabelTicketFreeText1').style.display = 'none';
      document.getElementById('TicketFreeText2').style.display = 'none';
      document.getElementById('LabelTicketFreeText2').style.display = 'none';
}
switch ($('#Dest').val() ) { //this is where the queue is relevant (Dest = Queue)
    case "17": // Queue ID as per the database
      document.compose.RichText.value = "Q a";
      nonetext();
      document.getElementById('TicketFreeText1').style.display = 'block';
      document.getElementById('LabelTicketFreeText1').style.display = 'block';
    break;
    case "18": //Queue ID as per the database
      document.compose.RichText.value = "Q b";
      nonetext();
      document.getElementById('TicketFreeText2').style.display = 'block';
      document.getElementById('LabelTicketFreeText2').style.display = 'block';
    break;
   default:
      document.compose.RichText.value = $('#Dest').val();
      document.getElementById('TicketFreeText1').style.display = 'none';
      document.getElementById('LabelTicketFreeText1').style.display = 'none';
      document.getElementById('TicketFreeText2').style.display = 'none';
      document.getElementById('LabelTicketFreeText2').style.display = 'none';
This way all works out perfectly.

I am sure now we can use States etc....Any value really...

Thanks...
Jakez
--------------
OTRS 3.0.9
ITSM 3.0.4
jakezp
Znuny newbie
Posts: 22
Joined: 10 Sep 2011, 09:39
Znuny Version: 3

Re: Display FreeText field based on State

Post by jakezp »

Thanks man...

Looks like we posted at the same time....

I got it working.

Thanks for all the assistance...

Would not have been able to do it without you pointing me in the correct direction....

Thanks
Jakez
--------------
OTRS 3.0.9
ITSM 3.0.4
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Display FreeText field based on State

Post by crythias »

You don't have to set Dest. You only have to switch on QueueID.

<input id="Dest" type="hidden" value="$Data{"QueueID"}" />
is the same concept as Dest.val = QueueID

and later ...
switch ($('#Dest').val() )
can simply be

switch ($Data{"QueueID"})
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
Locked