Problem with update dept from ldap action in RT Essentials

RT folks,

I’m trying to use the sample scrip on page 81 of RT Essentials that
updates custom field “Department” based on information retrieved from LDAP.
Condition: OnCreate, Action: User Defined (pasted code into action prep
code - see below), Template: Blank

I’m not sure how to debug this… The “base dn” is the same as we use
for our email clients ldap lookups. I have Net::LDAP installed from
CPAN… the rt.log file says:
[Wed Jan 4 20:10:40 2006] [error]: Scrip 154 Prepare failed: Can’t
locate object method “new” via package “Net::LDAP” (perhaps you forgot
to load “Net::LDAP”?) at (eval 2124) line 3.

How would I go about “loading” Net::LDAP?

I pasted the custom action and full rt.log error message below.

Thanks in advance for any tips.

Mike

My build (mostly from ports)
RT 3.2.2, Perl v5.8.4 under freebsd, Apache v1.27, FreeBSD 4.11,
mod_perl v1.29

my $email = ($self->TicketObj->RequestorAddresses)[0];
my $ldap = Net::LDAP->new( ‘directory.unex.berkeley.edu’ );
$ldap->bind;
my $msg = $ldap->search( base => ‘dc=unex,dc=berkeley,dc=edu’,
filter => “(email=$email)”,
);
my $entry = $msg->entry(0);
my $dept = $entry->get_value(‘ou’);
my $cf = RT::CustomField->new( $RT::SystemUser );
$cf->LoadByName( Name => ‘Department’ );
$self->TicketObj->AddCustomFieldValue( Field => $cf, Value =>
$dept );
return 1;

It doesn’t seem to work and I keep getting the same message in my rt.log
file:
[Wed Jan 4 20:10:40 2006] [error]: Scrip 154 Prepare failed: Can’t
locate object method “new” via package “Net::LDAP” (perhaps you forgot
to load “Net::LDAP”?) at (eval 2124) line 3.

Stack:
[(eval 2124):3]
[/usr/local/rt3/lib/RT/ScripAction_Overlay.pm:217]
[/usr/local/rt3/lib/RT/Scrip_Overlay.pm:468]
[/usr/local/rt3/lib/RT/Scrips_Overlay.pm:232]
[/usr/local/rt3/lib/RT/Transaction_Overlay.pm:146]
[/usr/local/rt3/lib/RT/Ticket_Overlay.pm:3707]
[/usr/local/rt3/lib/RT/Ticket_Overlay.pm:710]
[/usr/local/rt3/lib/RT/Interface/Web.pm:340]
[/usr/local/rt3/share/html/Ticket/Display.html:100]
[/usr/local/rt3/share/html/Ticket/Create.html:279]
[/usr/local/rt3/share/html/autohandler:221]
(/usr/local/rt3/lib/RT/Action/UserDefined.pm:65)

Mike Patterson
Systems Manager
UC Berkeley Extension

Hello!

How would I go about “loading” Net::LDAP?

Have you tried:

use Net::LDAP;

As in:


use Net::LDAP;

my $email = ($self->TicketObj->RequestorAddresses)[0];
my $ldap = Net::LDAP->new( ‘directory.unex.berkeley.edu’ );
$ldap->bind;
my $msg = $ldap->search( base => ‘dc=unex,dc=berkeley,dc=edu’,
filter => “(email=$email)”,
);
my $entry = $msg->entry(0);
my $dept = $entry->get_value(‘ou’);
my $cf = RT::CustomField->new( $RT::SystemUser );
$cf->LoadByName( Name => ‘Department’ );
$self->TicketObj->AddCustomFieldValue( Field => $cf, Value =>
$dept );
return 1;

I think that might work.

Cheers!

–j
Jim Meyer, Geek at Large purp@acm.org

Jim,

Thanks for the leading me in the right direction. I suppose that would
be obvious if I was much of a perl programmer.
After that I was on to the next bit of debugging (a couple more changes)
and now it’s working! :-)On my ldap server we call “email” “mail” filter => “(mail=$email)”, #filter => “(mail=$email)”, I was getting this message: [Thu Jan 5 17:39:48 2006] [error]: Scrip 154 Commit failed: RT::CustomField::LoadByName Unimplemented in RT::Action::UserDefined. ((eval 2322) line 17) So I looked at the API docs (Request Tracker Wiki) and I couldn’t find LoadByName on my version of RT (3.2.2). So I used LoadByNameAndQueue (Queue 0 is a what you choose if it’s a “global queue” which is what I’m using). $cf->LoadByNameAndQueue( Name => ‘Department’, Queue => ‘0’); #$cf->LoadByName( Name => ‘Department’ ); Does anyone know if there is an errata page for RT Essentials? The next thing I need to do figure out how is how to do this when the requestor changes (because people often submit for other people and then change the requestor later) and also search mailAlternateAddresses in ldap for those darn people that one email alias isn’t enough for. Thanks, Mike Jim Meyer wrote:

Hello!

On Wed, 2006-01-04 at 16:18, Mike Patterson wrote:

How would I go about “loading” Net::LDAP?

Have you tried:

use Net::LDAP;

Mike Patterson
Systems Manager
UC Berkeley Extension

$cf->LoadByNameAndQueue( Name => ‘Department’, Queue => ‘0’);
#$cf->LoadByName( Name => ‘Department’ );

Does anyone know if there is an errata page for RT Essentials?

http://www.oreilly.com/catalog/rtessentials/errata/

We’d love to hear about any errors you’ve caught.

Additionally, O’Reilly are readying a second printing, so anything you
see, we’d love to fix as quickly as possible. Of course, errata that
I’ve submitted haven’t been posted (and I did so over a month ago).

Jesse

Second printing? Does that mean sales are good?

Any possibility for RT, The Definitive Guide?

-Todd

Second printing? Does that mean sales are good?

Well, it means that they sold out the first print run. And I know my
mom only bought about five copies. We give away a copy to every
attendee of a training class (Amsterdam on Monday, Boston and SF coming
up soon.) I figure I’ve personally seen about 1% of all the RT
essentials books out there. The rest must be going somewhere.

Any possibility for RT, The Definitive Guide?

Write to your congressperson…er to O’Reilly telling them you’d buy a
couple hundred copies. If everybody does that, then maybe :wink: