Customize CustomerTicketMessage with TicketFreeText

English! place to talk about development, programming and coding
Post Reply
rtocci62
Znuny newbie
Posts: 15
Joined: 29 Jul 2013, 11:07
Znuny Version: 3.0.10

Customize CustomerTicketMessage with TicketFreeText

Post by rtocci62 »

Hi guys, I need to customize the form of insertion ticket from the customer panel.
I have configured the new attribute in TicketFreeText11 and I made sure that is visilbile only for a specific queue in CustomerTicketMessage.dtl:

Code: Select all

	switch ($('#Dest').val() ) { 
	case "36\|\|TBS-OP::Remote Services::Help Desk::XXXX": 
        document.compose.RichText.value ="<b>-PROBLEM :<br/>-CONTACT :<br/>-PHONE :<br/>-TIME:<br/>";
        document.getElementById('TicketFreeText11').style.display = 'block';
        document.getElementById('LabelTicketFreeText11').style.display = 'block';
        document.getElementById('TicketFreeText11').className = 'Validate_Required';
	     break;
 	default:
		document.getElementById('TicketFreeText11').style.display = 'none';
      		document.getElementById('LabelTicketFreeText11').style.display = 'none';
		document.compose.RichText.value = "";
	}
Now I want to implement an function that lists the assets on CMDB that match what you type in TicketFreeText11 (like from in AgentTicketPhone).
To simplify I would like to activate a select like this "SELECT DISTINCT(name) FROM configitem_version where mane like ?"
and return the result in TicketFreeText11.
Alternatively, even with the addition of a new button (Asset Search) to activate the select and return the list received in TicketFreeText11 for selection.
Someone has already developed something similar?

Hope I have described well the request (OTRS 3.0.10-ITSM 3.0.6)
Thanks
Rocco
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Customize CustomerTicketMessage with TicketFreeText

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
rtocci62
Znuny newbie
Posts: 15
Joined: 29 Jul 2013, 11:07
Znuny Version: 3.0.10

Re: Customize CustomerTicketMessage with TicketFreeText

Post by rtocci62 »

Thanks Crythias, I followed the instructions of your topic, but I have a problem to populate the select, the following code extdata.pl

Code: Select all

#!/usr/bin/perl -w
use strict;
use warnings;

use CGI qw(:standard);
#use JSON; #install JSON via cpan/ppm if you want to use it instead

print header(-type => 'application/json');

#code to query data

# use ../../ as lib location
use FindBin qw($Bin);
use lib "$Bin/../..";
use lib "$Bin/../../Kernel/cpan-lib";
use lib "$Bin/../../Custom";

use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Log;
use Kernel::System::Main;
use Kernel::System::DB;

   my %CommonObject = ();
   $CommonObject{ConfigObject} = Kernel::Config->new();
   $CommonObject{EncodeObject} = Kernel::System::Encode->new(%CommonObject);
   $CommonObject{LogObject}    = Kernel::System::Log->new(
    LogPrefix => 'ExtData',
    %CommonObject,
   );
   $CommonObject{MainObject}   = Kernel::System::Main->new(%CommonObject);
   $CommonObject{DBObject}     = Kernel::System::DB->new(
      %CommonObject,
	 DatabaseDSN  => 'DBI:mysql:database=otrs;host=localhost;',
	 DatabaseUser => 'otrs_1',
     DatabasePw   => 'otrs_1',
     Type         => 'mysql',
   );

   my $query = param('q') || '';
   my $like = '%' . $query . '%';
   my $ResultAsArrayRef = $CommonObject{DBObject}->Prepare(
      SQL => "SELECT DISTINCT(name),id FROM configitem_version WHERE name like ?",
      Bind => [ \$like ],
      Order => 'asc',
   );
#  my $json_text = to_json($ResultAsArrayRef);
#  print $json_text;
while ( my @Row = $CommonObject{DBObject}->FetchrowArray()) {
    print '<option value="' . $Row[0] . '">' ."$Row[0]</option>\n";
}
1; 
and the test page

Code: Select all

<html>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<body>
<h1>It Work!</h1>
<select id="myselect" name="myselect">
</select>
<script type="text/javascript" >
        $.get('localhost/otrs/extdata.pl', function(data) {
           $('#myselect').append(data);
		});
		alert( "AFTER JQUERY.GET" );
		alert( $('#myselect option').length );
</script>
</body>
</html>
the selct is empty, any ideas?
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Customize CustomerTicketMessage with TicketFreeText

Post by crythias »

yes. your query is seeking anything after an unpassed q parameter, per the example I've provided.


The gist of $.get('.../extadata.pl'...) results in: select [stuff] where name like '%%' ... this should return everything in configitem_version (though if you consistently want to return everything, you don't need a where clause...)

Code: Select all

   my $ResultAsArrayRef = $CommonObject{DBObject}->Prepare(
      SQL => "SELECT DISTINCT(name),id FROM configitem_version",
      Order => 'asc',
   );

you should also make sure that would legitimately return values.
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
rtocci62
Znuny newbie
Posts: 15
Joined: 29 Jul 2013, 11:07
Znuny Version: 3.0.10

Re: Customize CustomerTicketMessage with TicketFreeText

Post by rtocci62 »

OK, at the moment I just want to verify the get function of JQuery and then select (into extdata.pl) returns all records( only 3 CI).
When I launch into browser http://localhost/otrs/extdata.pl the result is' :

<option value="4613852">4613852</option>
<option value="4613853">4613853</option>
<option value="4613854">4613854</option>

but from the test page(index.tml), the list(3 Item) is not loaded in the field myselect.

Code: Select all

<html>
<script src ="http://localhost/otrs-web/js/thirdparty/jquery-1.4.4/jquery.js"></script>
<h1>It works</h1>

<select id="myselect" name="myselect">
</select>
<script type="text/javascript" >
        $.get('localhost/otrs/extdata.pl', function(data) {
           $('#myselect').append(data);
		});
		alert( "AFTER JQUERY.GET" );
		alert( $('#myselect option').length );
		$('#myselect').append('<option value="4613852">4613852</option>');
</script>
<body>
<html>
I tried turning on the console of crome but I can not understand how it works and why the get function does not return the list.

Thanks
Rocco
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Customize CustomerTicketMessage with TicketFreeText

Post by crythias »

you might want to try a more recent release of jquery.
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
Post Reply