ExtractCustomFieldValues, insert fixed value when match

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

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 = “”;
my $pw = “”;
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.
JoshOn Fri, May 4, 2012 at 5:51 AM, Stefan Stefanov ststefanov@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

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

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

Actually, I think you can just pass the field name into AddCustomFieldValue
and cut out looking up the name yourself. At least that’s what I’ve been
doing and it appears to work.

http://www.linkedin.com/in/paultomblin

Thanks for ideas, but I’m using extension ExtractCustomFieldValues
just as it’s described here:

http://wiki-archive.bestpractical.com/view/ExtractCustomFieldValues

Stefan Stefanov

Hi,

ECFV extension allows you to put code that changes value after match
to any value you like, but it’s not really job for this extension.
It’s better to use custom scrip for such thing.On Fri, May 4, 2012 at 1:51 PM, Stefan Stefanov ststefanov@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

Best regards, Ruslan.

In this case I have to write code which do almost the same work as
ECFV is doing (extract from incoming mail field “From:”).
I already use ECFV extension for filling other custom fields
and I think most efficient will be if I can use it for this field also.

Can someone post an example of such code in ECVF extension?On Fri, May 4, 2012 at 3:53 PM, Ruslan Zakirov ruz@bestpractical.com wrote:

Hi,

ECFV extension allows you to put code that changes value after match
to any value you like, but it’s not really job for this extension.
It’s better to use custom scrip for such thing.

On Fri, May 4, 2012 at 1:51 PM, Stefan Stefanov ststefanov@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


Best regards, Ruslan.

Stefan Stefanov

Thank you!

I made this way:

Scrip:
Condition: On Create
Action: User Defined
Template: GlobalTemplate: Blank
Stage: TransactionCreate

Custom action preparation code:

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_value;

set some other default values

$cf_obj->LoadByName(Name=>“CF1”);
$cf_value=“mail”;
$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$cf_value,
RecordTransaction=>0);

$cf_obj->LoadByName(Name=>“CF2”);
$cf_value=“Outstanding”;
$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$cf_value,
RecordTransaction=>0);

set value by requestor address

my $ticketRequestor = lc($ticket->RequestorAddresses);
$ticketRequestor =~ /(^.+)@([^.].*.[a-z]{2,}$)/;

#if ( $1 =~ /^username$/m ) {
#$self->TicketObj->AddCustomFieldValue( Field => ‘Region’, Value => ‘ONE’ );
#}

if ( $2 =~ /^domain1.local$/m ) {
$self->TicketObj->AddCustomFieldValue( Field => ‘DOMAIN’, Value => ‘Domain1’ );
}

return 1;

Next ExtractCustomFieldValues extension is started and custom field
values are set according incoming mail.

But my question was:

Is it possible to do same thing as last one using only template for
ExtractCustomFieldValues extension?
(for example some regex returning value ‘Domain1’ if incoming mail

Thanks again to all for help!
Stefan Stefanov