"What does this do?"
it's a very VERY rudimentary get data from external data source cgi. You can use it with jQuery (you will probably need to load jquery in HTMLHead.dtl) for data access to that thing you want - dynamicfields external data.
"How do I use it?"
create a file in /otrs/bin/cgi-bin, maybe call it "extdata.pl" ... give it execute permissions chmod +x 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:odbc:database=123;host=localhost;',
# DatabaseUser => 'user',
# DatabasePw => 'somepass',
# Type => 'mysql',
);
my $query = param('q') || '';
my $like = '%' . $query . '%';
my $ResultAsArrayRef = $CommonObject{DBObject}->Prepare(
SQL => "SELECT id, login FROM users WHERE login like ?",
Bind => [ \$like ],
Order => 'asc',
Limit => 10
);
# my $json_text = to_json($ResultAsArrayRef);
# print $json_text;
while ( my @Row = $CommonObject{DBObject}->FetchrowArray()) {
print '<option value="' . $Row[0] . '">'. $Row[1] . "</option>\n";
}
1;
Of course, you don't have to send a query parameter for filter, you could just make a fixed SELECT entry.
"What do I do with that?"
First, this is proof of concept, and it's my first go at it. It uses OTRS API to handle the calls, but generally all you will need is to provide the credentials and adjust the select to what you're looking for.
Then, you'll need something to call it.
A sample select is like this:
Code: Select all
<select id="myselect" name="DynamicField_fieldName">
</select>
Code: Select all
<script type="text/javascript">
$.get('extdata.pl', function(data) {
$('#myselect').append(data);
});
</script>
Hope this helps.
Bug fix requests here. Questions on implementation in the standard forums, please?
Also, it *might* be likely that a DynamicField_XXX configured as a dropdown/Select might be problematic if you provide values that aren't in the list.
An option to workaround this is to use a Dynamic Field that's a text input and change an input to a select or to use autocomplete/fuzzy search.