Scipts not working

Hi List,

RT: 3.6.7, debian5

sorry, I don’t know what I am doing wrong, it must be my lack of pearl
knowledge. I have the following scrip, with which I want to set a
customfield value via email contents:

Custom condition:

my $AttachObj = $self->TransactionObj->Attachments->First;

if (($self->TransactionObj->Type eq “Create”) && ($AttachObj->Content =~
/RT-Set-Test:/)) {
return(1);
} else {
return(undef);
}

Custom action prep code:

$RT::Logger->info(“Automagic Ticket change”);
1;

my $AttachObj = $self->TransactionObj->Attachments->First;

go out if content is not text!

unless( $AttachObj->ContentType =~ /^text/ ) {

  return 1;

}

my $content = $AttachObj->Content;
if( $content =~ m/^\QRT-Set-Test:\E\s*(\S+)\s*$/m ) {

  $self->TicketObj->AddCustomFieldValue( Field => 'muethos-test: 

test’, Value => $1 );
}

strip special commands from email content

$content =~ s/^\QRT-Set-Test:\E\s*(\S+)\s*$//gm;

silently overwrite attachment content

$AttachObj->__Set( Field => ‘Content’, Value => $content );

1;

Custom action cleanup code:

return( 1 );

My customfield is: “enter one value” (I also tried "enter multiple values)

If I send an email with the following contents

RT-Set-Test: Test

it works perfectly fine, my customfield “muethos-test: test” contains Test.

But I want more than just one word, I tried the following:

RT-Set-Test: Test 1
RT-Set-Test: ‘Test 1’
RT-Set-Test: “Test 1”
RT-Set-Test:‘Test 1’

all of them do not work.

Can anyone help me?

Thanks a lot.
Violetta

________________________________ creating IT solutions
Violetta J. Wawryk science + computing ag
IT-Service Hagellocher Weg 73
phone +49 7071 9457 282 72070 Tuebingen, Germany
fax +49 7071 9457 211 www.science-computing.de
Vorstand/Board of Management:
Dr. Bernd Finkbeiner, Dr. Roland Niemeier,
Dr. Arno Steitz, Dr. Ingrid Zech
Vorsitzender des Aufsichtsrats/
Chairman of the Supervisory Board:
Michel Lepert
Sitz/Registered Office: Tuebingen
Registergericht/Registration Court: Stuttgart
Registernummer/Commercial Register No.: HRB 382196

Try change the regexp from
$content =~ m/^\QRT-Set-Test:\E\s*(\S+)\s*$/m
to
$content =~ /RT-Set-Test:\s*(.+)$/mg;

-ChrisAm 24.03.2011 11:17, schrieb Violetta J. Wawryk:

Hi List,

RT: 3.6.7, debian5

sorry, I don’t know what I am doing wrong, it must be my lack of pearl
knowledge. I have the following scrip, with which I want to set a
customfield value via email contents:


Custom condition:

my $AttachObj = $self->TransactionObj->Attachments->First;

if (($self->TransactionObj->Type eq “Create”) && ($AttachObj->Content =~
/RT-Set-Test:/)) {
return(1);
} else {
return(undef);
}


Custom action prep code:

$RT::Logger->info(“Automagic Ticket change”);
1;

my $AttachObj = $self->TransactionObj->Attachments->First;

go out if content is not text!

unless( $AttachObj->ContentType =~ /^text/ ) {

 return 1;

}

my $content = $AttachObj->Content;
if( $content =~ m/^\QRT-Set-Test:\E\s*(\S+)\s*$/m ) {

 $self->TicketObj->AddCustomFieldValue( Field => 'muethos-test:

test’, Value => $1 );
}

strip special commands from email content

$content =~ s/^\QRT-Set-Test:\E\s*(\S+)\s*$//gm;

silently overwrite attachment content

$AttachObj->__Set( Field => ‘Content’, Value => $content );

1;


Custom action cleanup code:

return( 1 );


My customfield is: “enter one value” (I also tried "enter multiple values)

If I send an email with the following contents

RT-Set-Test: Test

it works perfectly fine, my customfield “muethos-test: test” contains Test.

But I want more than just one word, I tried the following:

RT-Set-Test: Test 1
RT-Set-Test: ‘Test 1’
RT-Set-Test: “Test 1”
RT-Set-Test:‘Test 1’

all of them do not work.

Can anyone help me?

Thanks a lot.
Violetta

Christian,

First, I’d re-arrange your code and simplify it. Start by using RT’s
standard condition “On Create”. That other stuff is just redundant to what
you want to do and that clutters the logic flow.
Then, I’d make the logic in your Custom Prep Code area more linear, or “top
down”. This type of code let’s you test for all the conditions you “Don’t”
want, 1 at a time, in order to get out. If all those conditions fail, you
can then do your thing. It also makes code easier to follow & debug:

Custom Action Prep Code:

set regular values

my $ticket = $self->TicketObj;
my $trans = $self->TransactionObj;
my $AttachObj = $trans->Attachments->First;
my $content = $AttachObj->Content;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = “muethos-test:test”;
my $cf_value;

Get out of Content isn’t “whatever”

return unless ($AttachObj->Content =~/RT-Set-Test:/);
$RT::Logger->info(“Passed first test”);

Get out of Content Type isn’t “text”, although I don’t know why you need

this when the one above seems sufficient

return unless ($AttachObj->ContentType =~ /^text/);
$RT::Logger->info(“Passed second test”);

Get out for another reason

return unless ($content =~ m/^\QRT-Set-Test:\E\s*(\S+)\s*$/m);
$RT::Logger->info(“Passed third test”);

Build Content value

$content =~ s/^\QRT-Set-Test:\E\s*(\S+)\s*$//gm;

Now put the new $content value into your CF

$cf_obj->LoadByName(Name=>$cf_name);
$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n”);
$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$content,
RecordTransaction=>0);

return 1;

Custom Action Cleanup Code:

return 1;

I didn’t check the regexp syntax, I just wanted to show you a way to write
the code so it flows top down without redundancy. It just makes it way
easier to debug cause you can put Logger comments in each step and follow
what is happening.

Hope this helps.

Kenn
LBNLOn Thu, Mar 24, 2011 at 6:54 AM, Christian Loos cloos@netcologne.de wrote:

Try change the regexp from
$content =~ m/^\QRT-Set-Test:\E\s*(\S+)\s*$/m
to
$content =~ /RT-Set-Test:\s*(.+)$/mg;

-Chris

Am 24.03.2011 11:17, schrieb Violetta J. Wawryk:

Hi List,

RT: 3.6.7, debian5

sorry, I don’t know what I am doing wrong, it must be my lack of pearl
knowledge. I have the following scrip, with which I want to set a
customfield value via email contents:


Custom condition:

my $AttachObj = $self->TransactionObj->Attachments->First;

if (($self->TransactionObj->Type eq “Create”) && ($AttachObj->Content =~
/RT-Set-Test:/)) {
return(1);
} else {
return(undef);
}


Custom action prep code:

$RT::Logger->info(“Automagic Ticket change”);
1;

my $AttachObj = $self->TransactionObj->Attachments->First;

go out if content is not text!

unless( $AttachObj->ContentType =~ /^text/ ) {

 return 1;

}

my $content = $AttachObj->Content;
if( $content =~ m/^\QRT-Set-Test:\E\s*(\S+)\s*$/m ) {

 $self->TicketObj->AddCustomFieldValue( Field => 'muethos-test:

test’, Value => $1 );
}

strip special commands from email content

$content =~ s/^\QRT-Set-Test:\E\s*(\S+)\s*$//gm;

silently overwrite attachment content

$AttachObj->__Set( Field => ‘Content’, Value => $content );

1;


Custom action cleanup code:

return( 1 );


My customfield is: “enter one value” (I also tried "enter multiple
values)

If I send an email with the following contents

RT-Set-Test: Test

it works perfectly fine, my customfield “muethos-test: test” contains
Test.

But I want more than just one word, I tried the following:

RT-Set-Test: Test 1
RT-Set-Test: ‘Test 1’
RT-Set-Test: “Test 1”
RT-Set-Test:‘Test 1’

all of them do not work.

Can anyone help me?

Thanks a lot.
Violetta