Hi,

I tried your suggestion and it doesn't work, RT complains:

[3270] [Thu Feb  6 12:50:36 2014] [error]: Scrip 25 IsApplicable failed: Can't 
locate object method "First" via package "No object mapping for field" (perhaps 
you forgot to load "No object mapping for field"?) at (eval 792) line 20.

When I try this code, it runs but it's not outputting what I need:
my $trueuser = $TicketObj->Requestors->UserMembersObj->First->RealName;
$RT::Logger->debug("trueuser is: ".$trueuser);

Resulting output looks to be whatever is before the "@" in the email address, 
not the RealName:

[3263] [Thu Feb  6 12:55:07 2014] [debug]: trueuser is: ethier ((eval 625):28)

Any other ideas ?

Thanks,
Mike


From: Landon Stewart [mailto:[email protected]]
Sent: Wednesday, February 05, 2014 2:50 PM
To: Ethier, Michael
Cc: [email protected]
Subject: Re: [rt-users] How to grab requestor's first and last name in email 
address ?

On 5 February 2014 11:16, Ethier, Michael 
<[email protected]<mailto:[email protected]>> wrote:
Hello,

I need to obtain the first and last name that would be part of the requestor's 
email address.
For example, requestor email address comes in as:

From: "Smith, Joe" <[email protected]<mailto:[email protected]>>

In this example I want parse out the "Joe" and "Smith" keywords and assign them 
to 2 variables
which I will use for comparison later.

I am writing a RT Scrip. Is this possible to do ?

The "name" of the requestor is stored within the UsersObj in the Requestors 
group object for the $Ticket.  You want the first UsersObj.  There's no way to 
know if it's the name is written "Last, First" or "First Last" so you'll have 
to figure that out somehow.  Usually a comma in a name field means "Last, 
First" though so the following is a decent bet.  I haven't tested this code but 
this ought to get you close anyway.

my $realname = $self->TicketObj->Requestors->UsersObj->First->RealName;
# Switch things around if there's a comma in the field.
$realname =~ s/(.*),\s*(.*)/$2 $1/ if $realname =~ /,/;

If they have "First Last, Company" it'll come out as "ACME Inc., Jim Smith" 
though which might not be terrible.
Worse would be "Last, First - Position" coming out as "Jim - Manager Smith" 
which might sound a little too familiar for business.

In my opinion you'd want to just leave it as-is so if it's Last, First and they 
get an email addressed to them with "Dear Smith, Jim:" they'll know it's 
because they have it that way in their mail client.

--
Landon Stewart :: [email protected]<mailto:[email protected]>
Lead Specialist, Abuse and Security Management
Spécialiste principal, gestion des abus et sécurité
http://iweb.com :: +1 (888) 909-4932


Reply via email to