Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Request Tracker: Users

ExtractCustomFieldValues, insert fixed value when match

 

 

Request Tracker users RSS feed   Index | Next | Previous | View Threaded


ststefanov at gmail

May 4, 2012, 2:51 AM

Post #1 of 7 (469 views)
Permalink
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


jlaroff at gmail

May 4, 2012, 3:11 AM

Post #2 of 7 (448 views)
Permalink
Re: ExtractCustomFieldValues, insert fixed value when match [In reply to]

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> 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


ptomblin at xcski

May 4, 2012, 3:46 AM

Post #3 of 7 (447 views)
Permalink
Re: ExtractCustomFieldValues, insert fixed value when match [In reply to]

On Fri, May 4, 2012 at 6:11 AM, Joshua Laroff <jlaroff [at] gmail> wrote:

> 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
http://careers.stackoverflow.com/ptomblin


ststefanov at gmail

May 4, 2012, 4:23 AM

Post #4 of 7 (441 views)
Permalink
Re: ExtractCustomFieldValues, insert fixed value when match [In reply to]

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

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

--
Stefan Stefanov


ruz at bestpractical

May 4, 2012, 5:53 AM

Post #5 of 7 (445 views)
Permalink
Re: ExtractCustomFieldValues, insert fixed value when match [In reply to]

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 [at] gmail> 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.


ststefanov at gmail

May 4, 2012, 6:01 AM

Post #6 of 7 (447 views)
Permalink
Re: ExtractCustomFieldValues, insert fixed value when match [In reply to]

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 [at] bestpractical> 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 [at] gmail> 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


ststefanov at gmail

May 8, 2012, 2:01 AM

Post #7 of 7 (386 views)
Permalink
Re: ExtractCustomFieldValues, insert fixed value when match [In reply to]

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
From: field is .*@domain1.local)

Thanks again to all for help!
--
Stefan Stefanov

Request Tracker users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.