Christian,<br><br>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.<br>
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:<br>
<br>Custom Action Prep Code:<br># set regular values<br><br>my $ticket = $self->TicketObj;<br>my $trans = $self->TransactionObj;<br>my $AttachObj = $trans->Attachments->First;<br>my $content = $AttachObj->Content;<br>
my $cf_obj = RT::CustomField->new($RT::SystemUser);<br>my $cf_name = "muethos-test:test";<br>my $cf_value;<br><br># Get out of Content isn't "whatever"<br><br>return unless ($AttachObj->Content =~/RT-Set-Test\:/);<br>
$RT::Logger->info("Passed first test");<br><br># Get out of Content Type isn't "text", although I don't know why you need this when the one above seems sufficient<br>
<br>
return unless ($AttachObj->ContentType =~ /^text/);<br>$RT::Logger->info("Passed second test");<br><br># Get out for another reason<br><br>return unless ($content =~ m/^\QRT-Set-Test:\E\s*(\S+)\s*$/m);<br>
$RT::Logger->info("Passed third test");<br><br># Build Content value<br>
<br>
$content =~ s/^\QRT-Set-Test:\E\s*(\S+)\s*$//gm;<br><br># Now put the new $content value into your CF<br><br>$cf_obj->LoadByName(Name=>$cf_name);<br>$RT::Logger->debug("Loaded\$cf_obj->Name = ". $cf_obj->Name() ."\n");<br>
$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$content, RecordTransaction=>0);<br><br>return 1;<br><br>Custom Action Cleanup Code:<br><br>return 1;<br><br>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.<br>
<br>Hope this helps.<br><br>Kenn<br>LBNL<br><br><br><div class="gmail_quote">On Thu, Mar 24, 2011 at 6:54 AM, Christian Loos <span dir="ltr"><<a href="mailto:cloos@netcologne.de">cloos@netcologne.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Try change the regexp from<br>
<div class="im">$content =~ m/^\QRT-Set-Test:\E\s*(\S+)\s*$/m<br>
</div>to<br>
$content =~ /RT-Set-Test:\s*(.+)$/mg;<br>
<br>
-Chris<br>
<br>
Am <a href="tel:24.03.2011%2011">24.03.2011 11</a>:17, schrieb Violetta J. Wawryk:<br>
<div><div></div><div class="h5">> Hi List,<br>
><br>
> RT: 3.6.7, debian5<br>
><br>
> sorry, I don't know what I am doing wrong, it must be my lack of pearl<br>
> knowledge. I have the following scrip, with which I want to set a<br>
> customfield value via email contents:<br>
><br>
> ***************************************************<br>
> Custom condition:<br>
><br>
> my $AttachObj = $self->TransactionObj->Attachments->First;<br>
><br>
> if (($self->TransactionObj->Type eq "Create") && ($AttachObj->Content =~<br>
> /RT-Set-Test\:/)) {<br>
> return(1);<br>
> } else {<br>
> return(undef);<br>
> }<br>
><br>
> ***************************************************<br>
> Custom action prep code:<br>
><br>
> $RT::Logger->info("Automagic Ticket change");<br>
> 1;<br>
><br>
> my $AttachObj = $self->TransactionObj->Attachments->First;<br>
> # go out if content is not text!<br>
> unless( $AttachObj->ContentType =~ /^text/ ) {<br>
><br>
> return 1;<br>
> }<br>
><br>
> my $content = $AttachObj->Content;<br>
> if( $content =~ m/^\QRT-Set-Test:\E\s*(\S+)\s*$/m ) {<br>
><br>
> $self->TicketObj->AddCustomFieldValue( Field => 'muethos-test:<br>
> test', Value => $1 );<br>
> }<br>
><br>
> # strip special commands from email content<br>
> $content =~ s/^\QRT-Set-Test:\E\s*(\S+)\s*$//gm;<br>
><br>
> # silently overwrite attachment content<br>
> $AttachObj->__Set( Field => 'Content', Value => $content );<br>
><br>
> 1;<br>
> ***************************************************<br>
><br>
> Custom action cleanup code:<br>
><br>
> return( 1 );<br>
><br>
> ***************************************************<br>
><br>
><br>
> My customfield is: "enter one value" (I also tried "enter multiple values)<br>
><br>
> If I send an email with the following contents<br>
><br>
><br>
> RT-Set-Test: Test<br>
><br>
><br>
> it works perfectly fine, my customfield "muethos-test: test" contains Test.<br>
><br>
> But I want more than just one word, I tried the following:<br>
><br>
><br>
> RT-Set-Test: Test 1<br>
> RT-Set-Test: 'Test 1'<br>
> RT-Set-Test: "Test 1"<br>
> RT-Set-Test:'Test 1'<br>
><br>
> all of them do not work.<br>
><br>
> Can anyone help me?<br>
><br>
> Thanks a lot.<br>
> Violetta<br>
><br>
><br>
><br>
</div></div></blockquote></div><br>