[rt-users] TransactionBatch scrip trouble

Gene LeDuc gleduc at mail.sdsu.edu
Thu Apr 12 11:39:48 EDT 2007


This may not be the problem, but you're using the wrong comparison 
operator.  When comparing strings in perl, use "eq" instead of "==" for the 
comparison operator (and "ne" instead of "!=" for inequalities).

At 04:26 PM 4/11/2007, Borut Mrak wrote:
>Hello,
>
>I must be blind or something... Why is this happening:
>
>Scrip Fields
>Description: WaitingField
>Condition: User Defined
>Action: User Defined
>Template: Global template: Blank
>Stage: TransactionBatch
>
>Custom Condition: return 1
>Custom Action Preparation Code:
>================================
>my @batch = @{ $self->TicketObj->TransactionBatch };
>
>my $cf = RT::CustomField->new( $RT::SystemUser );
>$cf->LoadByName( Name => 'WaitingForOwner' );
>
>my $doit = 0;
>foreach my $txn ( @batch ) {
>   $RT::Logger->debug("CF: txid " . $txn->id . " Type " . $txn->Type);
>   if ($txn->Type == "CustomField" and $txn->Field eq $cf->id) {
>     $RT::Logger->debug("CF: do not touch the field, user (or another
>Scrip) did it on his own in txid " . $txn->id);
>     return 0;
>   }
>   if ($txn->Type == "Create") {$RT::Logger->debug("CREATE" . $txn->Type);
>$doit = 1;}
>   if ($txn->Type == "Correspond") {$RT::Logger->debug("CORRESPOND" .
>$txn->Type); $doit = 1;}
>   if ($txn->Type == "Steal") {$RT::Logger->debug("STEAL" . $txn->Type);
>$doit = 1;}
>   if ($txn->Type == "Give") {$RT::Logger->debug("GIVE" . $txn->Type);
>$doit = 1;}
>}
>
>$RT::Logger->debug("CF: preparation returning $doit");
>return $doit;
>============================================
>Custom action cleanup code:
>==========================================
>my @batch = @{ $self->TicketObj->TransactionBatch };
>
># Load the CF
>my $cf = RT::CustomField->new( $RT::SystemUser );
>$cf->LoadByName( Name => 'WaitingForOwner' );
>
>foreach my $txn ( @batch ) {
>   $RT::Logger->debug("CF WaitingField: Transaction id:" . $txn->id . "
>Type: " . $txn->Type);
>
>   if ($txn->Type == "Give" or $txn->Type == "Steal" or $txn->Type ==
>"Create") {
>     $RT::Logger->debug("CF: setting to waiting on " . $txn->Type);
>     $self->TicketObj->AddCustomFieldValue(Field => $cf, Value =>
>'Waiting', RecordTransaction => 0);
>     return 1;
>   }
>   if ($txn->Type == "Correspond") {
>     my $ownerid = $self->TicketObj->Owner;
>     my $actorid = $txn->Creator;
>     # set it to answered if owner responded, but do not exit, since there
>     # might be a Give or Steal or something like that after this
>     # transaction.
>     if ($ownerid == $actorid) {
>       $RT::Logger->debug('CF: Set custom field to answered on ' .
>$txn->Type . 'from owner');
>       $self->TicketObj->AddCustomFieldValue(Field => $cf, Value =>
>'answered', RecordTransaction => 0);
>     }
>   }
>}
>return 1;
>=======================================================
>
>
>And I get this when I submit a comment:
>
>[Wed Apr 11 22:52:10 2007] [debug]: CF: txid 116504 Type Comment ((eval
>32755):8)
>[Wed Apr 11 22:52:10 2007] [debug]: CREATEComment ((eval 32755):13)
>[Wed Apr 11 22:52:10 2007] [debug]: CORRESPONDComment ((eval 32755):14)
>[Wed Apr 11 22:52:10 2007] [debug]: STEALComment ((eval 32755):15)
>[Wed Apr 11 22:52:10 2007] [debug]: GIVEComment ((eval 32755):16)
>
>
>Any clues? When user changes the custom field, the preparation works as
>intended (it returns 0), but it somehow works on Comment, while it should
>only work on Create, Correspond, Steal or Give.
>
>Thanks,
>Borut Mrak.
>_______________________________________________
>http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>
>Community help: http://wiki.bestpractical.com
>Commercial support: sales at bestpractical.com
>
>
>Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
>Buy a copy at http://rtbook.bestpractical.com


-- 
Gene LeDuc, GSEC
Security Analyst
San Diego State University 




More information about the rt-users mailing list