[rt-users] ExtractCustomFieldValues, insert fixed value when match

Joshua Laroff jlaroff at gmail.com
Fri May 4 06:11:00 EDT 2012


Hi Stefan,
We do something similar. I am sure there may be a better way to do
this but I am new to RT (and perl).
I needed to add a column to to the CustomFieldValues table called "email"

Here it is:
Condition: On Create
Action: User defined
Stage: TransactionCreate

Custom action preparation code:
return 1;

my $requester_email = ($self->TicketObj->RequestorAddresses)[0];
$requester_email =~ /(^.+)@([^\.].*\.[a-z]{2,}$)/;
my $email = $2;

my $cf = RT::CustomField->new($RT::SystemUser);
$cf->LoadByName(Name => 'Customer');

use Mysql;
my $host = "localhost";
my $database = "rt3";
my $tablename = "CustomFieldValues";
my $user = "<user>";
my $pw = "<password>";
my $connect = Mysql->connect($host, $database, $user, $pw);
$connect->selectdb($database);
my $myquery = "SELECT Name FROM $tablename WHERE email='$email'";
my $execute = $connect->query($myquery);
my @results = $execute->fetchrow();
my $result = $results[0];

$self->TicketObj->AddCustomFieldValue(Field => $cf, Value => $result);
return 1;

Hopefully this is what you were looking for.
Josh

On Fri, May 4, 2012 at 5:51 AM, Stefan Stefanov <ststefanov at gmail.com> wrote:
> Hello
>
> I need to set a custom field (for example CF1) with fixed value (for
> example "Domain1") if incoming mail from address is *@domain1.com
>
> I didn't found anything such case.
>
> How to do this?
>
> Best regards
> --
> Stefan



More information about the rt-users mailing list