[rt-users] External Custom Field query based an other Custom Field value

DupondEt Dupont jean.mich.c at gmail.com
Fri Aug 24 06:32:48 EDT 2012


Hi all,

i recently install lastest RT 4 release and start setting up external
custom fields from an Oracle query. (as describe in
docs/extending/external_custom_fields.pod)

Everything work really fine, until i decided to use previously filled
custom fied as argument in an other external custom field search.

In this study case ;) , both custom fields are assigned to ticket.
The first external CF (name Client) retrieve customer list and CF store the
value I have select.
The second external CF (name Machine) should retrieve hostname for the
customer select in CF Client...

Here is the piece of PERL code for CF Machine
(/opt/rt4/lib/RT/CustomFieldValues/Test2.pm)
-----------------------------------------------------------------------------
package RT::CustomFieldValues::Test2;

use strict;
use warnings;
use DBI;
use DBD::Oracle;
use base qw(RT::CustomFieldValues::External);

sub SourceDescription {
    return 'test2';
}

sub ExternalValues {
        my $self = shift;
# the previsous custom field name
        my $CFName = 'Client';
# should store the name of my customer...
        my $CFClient = $self->TicketObj->FirstCustomFieldValue($CFName);
        my $i = 0;
        my @res;
        my $Hostname
        my $dbh =
DBI->connect("dbi:Oracle:host=XXX.XXX.XXX.XXX;sid=XX;port=XXXX","XXXX","XXXX",
{ora_session_mode => 0, PrintError =>0});
        my $req = "SELECT distinct HOSTNAME FROM my_table where
CLIENT='$CFClient'";
        my $hreq = $dbh->prepare($req);
        $hreq->execute();;
        $hreq->bind_columns(\$Hostname);
        while ($hreq->fetch()){
                push @res, {
                    name        => $Hostname,
                    description => $Hostname,
                    sortorder   => $i++,
                };
        }
        return \@res;
}
-----------------------------------------------------------------------------

I used $self->TicketObj->FirstCustomFieldValue($CFName) but it's not know
in this context apparently as Data::Dumper shows me...(but
$self->CurrentUser is)

I hope you'll have a solution to deal with this, cause i got no more ideas.

Thank you in advance for your time.

JMC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20120824/a261d365/attachment.htm>


More information about the rt-users mailing list