[rt-users] TransactionBatch scrip trouble
Borut Mrak
b at aufbix.org
Wed Apr 11 19:26:11 EDT 2007
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.
More information about the rt-users
mailing list