TransactionBatch scrip trouble

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.

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.


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@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

PEBKAC, as usual :slight_smile: 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 :slight_smile:

thanks a lot,
Borut Mrak.

Gene LeDuc wrote: