[rt-users] Need LDAP scrip help: using a switch statement

Jacob Helwig Jacob at buschs.com
Tue Aug 21 08:43:06 EDT 2007


"switch" isn't really built into Perl, you have to "use Switch;".  I've
never tried using Perl modules from within the scrip custom
condition/action/etc, though.  I don't know of a reason, off hand, that
it wouldn't work though.

-- 
Jacob Helwig
PC Technician
Busch's Help Desk
Desk: x35221
Direct: 734-214-8221

-----Original Message-----
From: rt-users-bounces at lists.bestpractical.com
[mailto:rt-users-bounces at lists.bestpractical.com] On Behalf Of Tim
Wilson
Sent: Monday, August 20, 2007 8:35 PM
To: rt-users at lists.bestpractical.com
Subject: [rt-users] Need LDAP scrip help: using a switch statement

Hey everyone,

I'm trying to adapt the "set custom field with LDAP query" scrip example
from the RT book, and I'm stuck. I'm hoping someone has a suggestion.
The main problem, I'm afraid, is a lack of perl experience.

I've created a new scrip called "Set Building CF from LDAP on Create"
with Condition "On Create" and Action "User Defined". Here's my custom
action preparation code:

my $email = ($self->TicketObj->RequestorAddresses)[0];
my $ldap = Net::LDAP->new( 'my.ldap.server );
$ldap->bind;
my $msg = $ldap->search( base   => 'ou=Staff,o=My-ldap-org',
                         filter => '(email=$email)',
                       );
my $entry = $msg->entry(0);
my $ou = $entry->get_value('ou');

# Fix up the CF names based on LDAP results
switch ($ou) {
    case "DISTRICT SERVICES"  { $building = "DO" }
    case "HIGH SCHOOL"        { $building = "HS" }
    case "JEFFERSON"          { $building = "JES" } 
    else                      { $building = "DO" }
};

my $cf = RT::CustomField->new( $RT::SystemUser );
$cf->LoadByName( Name => 'Building' );
$self->TicketObj->AddCustomFieldValue( Field => $cf, Value => $building
);

return 1;

I don't have anything in the Custom action cleanup code box.

I'm trying to use a switch because the field in our LDAP records doesn't
match the custom field text in RT. Rather than changing everything in
the LDAP, I was hoping to make the translation here in the scrip action.

Anyone see a problem with this scrip? It doesn't seem to break anything,
but neither does the custom field get set when a new ticket comes in.

Running RT 3.6.3 on Ubuntu with MySQL 5.0.22 and apache-ssl 1.3.34

-Tim


-- 
Tim Wilson, Director of Technology
Buffalo-Hanover-Montrose Schools
214 1st Ave NE   Buffalo, MN  55313
ph: 763.682.8740  fax: 763.682.8743  http://www.buffalo.k12.mn.us




_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: sales at bestpractical.com


Discover RT's hidden secrets with RT Essentials from O'Reilly Media. 
Buy a copy at http://rtbook.bestpractical.com




More information about the rt-users mailing list