[rt-users] TransactionBatch scrip trouble
Borut Mrak
b at aufbix.org
Thu Apr 12 13:24:43 EDT 2007
PEBKAC, as usual :) I knew it had to be something stupid. It's been a few
years since I coded anything useful in Perl and I mixed the string and
numeric comparison operators. I somehow thought eq, ne and friends were
numeric operators, but it's the other way around.
Guess it's time to reread the Llama book :)
thanks a lot,
Borut Mrak.
Gene LeDuc wrote:
> 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
>
>
More information about the rt-users
mailing list