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

Tim Wilson twilson at buffalo.k12.mn.us
Mon Aug 20 20:34:32 EDT 2007


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







More information about the rt-users mailing list