Unexpected TransactionObj New/OldValue changes

Hi All,

I’m trying to assign a Custom Field only when tickets are changed to Queue 5 or 8. If I set the Scrip stage to Normal, my code works and sets the CF but, the CF is set back to its original value at the end of transaction:

Ticket History:
#2020-01-19 05:46 root (Enoch Root) - Queue changed from Noc-QA-Close to Noc-1NewTickets
#2020-01-19 05:46 The RT System itself - T_Retriage 1 changed to 2
#2020-01-19 05:46 The RT System itself - Status changed from ‘open’ to ‘new’
#2020-01-19 05:46 root (Enoch Root) - T_Retriage 2 changed to 1

If I set the Scrip stage to Batch, it works only if I DO NOT change ticket Status at the same time; If I do set Status at the same time, my code fails because TransactionObj->OldValue and NewValue are not the queue IDs anymore (but the new/old statuses)…

I’m using RT 4.4.4.

Any suggestion?
Thank you!

My Action commit code:

my $self = shift;
my $queueold = $self->TransactionObj->OldValue;
my $queuenew = $self->TransactionObj->NewValue;
my $cfT_Retriage = $self->TicketObj->CustomFieldValuesAsString(“T_Retriage”);
$RT::Logger->debug( “>>>> TRANSACTION TYPE: “. $self->TransactionObj->Type .” <<<<\n” );
$RT::Logger->debug( “>>>> TRANSACTION FIELD: “. $self->TransactionObj->Field .” <<<<\n” );
$RT::Logger->debug( “>>>> TRANSACTION OLD VALUE: “. $queueold .” <<<<\n” );
$RT::Logger->debug( “>>>> TRANSACTION NEW VALUE: “. $queuenew .” <<<<\n” );

if (($queuenew eq 5) || ($queuenew eq 8)) {
$RT::Logger->debug( “>>>> TICKET QUEUE (new 5/8) <<<<\n” );

Inc T_Retriage

$RT::Logger->debug( “>>>> cf T_Retriage Old: “. $cfT_Retriage .” <<<<\n” );
if ($cfT_Retriage eq “”) {$cfT_Retriage = 0;}
$cfT_Retriage = $cfT_Retriage + 1;
$RT::Logger->debug( “>>>> cf T_Retriage New: “. $cfT_Retriage .” <<<<\n” );
my ($ret, $msg) = $self->TicketObj->AddCustomFieldValue(Field => ‘T_Retriage’, Value => $cfT_Retriage);
$RT::Logger->debug( “>>>> ret “. $ret .” with msg “. $msg .” <<<<\n” );
$cfT_Retriage = $self->TicketObj->CustomFieldValuesAsString(“T_Retriage”);
$RT::Logger->debug( “>>>> cf T_Retriage Now: “. $cfT_Retriage .” <<<<\n” );
}

return 1;

Debug logger (When Queue change goes with Status Change):

TRANSACTION TYPE: Status <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:28)
TRANSACTION FIELD: Status <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:29)
TRANSACTION OLD VALUE: open <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:31)
TRANSACTION NEW VALUE: new <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:32)

Debug logger (When Queue change goes alone):

TRANSACTION TYPE: Set <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:28)
TRANSACTION FIELD: Queue <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:29)
TRANSACTION OLD VALUE: 7 <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:31)
TRANSACTION NEW VALUE: 5 <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:32)
TICKET QUEUE (new 5/8) <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:58)
cf T_Retriage Old: 1 <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:60)
cf T_Retriage New: 2 <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:63)
ret 1296 with msg T_Retriage 1 changed to 2 <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:65)
cf T_Retriage Now: 2 <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:67)

Initial data

@ScripActions = (
{ Name => ‘Set CFs Q Change’,
Description => ‘Set CFs Q Change’,
ExecModule => ‘SetCFsQChange’,
Argument => ‘’,
},
);

@Scrips = (
{ Queue => 0,
Description => ‘Set retriage CFs on Q Change’,
ScripCondition => ‘On Queue Change’,
ScripAction => ‘Set CFs Q Change’,
Template => ‘Blank’,
Stage => ‘TransactionBatch’,

},
);

I know the behavior with the batch more was a bug that recently got fixed with this commit I believe

I don’t see why the CF value would be set back to its original value after the normal mode script runs, do you have a transaction for that or know why? Maybe in the debug logs you can see if another script is setting the value back?

In your scrip you could check that the operation in the transaction is a queue set using a condition in an if statement along the lines of:

if ($self->TransactionObj->Type eq "Set" && $self->TransactionObj->Field eq "Queue") {
  # Do stuff
}

GreenJimll,

This condition is tested on ScripCondition => ‘On Queue Change’… No ideia why it reaches scrip as “Status”… If I test this on the scrip, it will never run…

Thanks.

knation, thank you for your help!

I tried this patch, same results… in Batch Transaction Type/Field = Status and Old/New are Status instead Queues IDs.

Regarding the Stage Normal mode, I guess the User Interface wins any CF setting (even if it is not a change)… Log shows my scrip incrementing the CF. Web UI and Ticket history shows User changing its queue, “The RT System itself” incrementing the CF, and then the “user” setting it back (to its original value)…

BTW, I have just tried to set the CF to 4 (it was 1) when changing the queue; Log showed my scrip incrementing the CF it from 1 to 2 and then the user setting it to 4 (from 2)… So Scrip runs before User Interface.

Debug log (stage normal, and only queue change):

Scrip 13 the original (On transaction, add any tags in the transaction’s subject to the ticket’s subject)
Scrip 28 is my SetCFsQChange…

(Full date eliminated to make it smaller)
[05:46:47]: About to prepare scrips for transaction #8045 (/opt/rt4/sbin/…/lib/RT/Transaction.pm:189)
[05:46:47]: Found 4 scrips for TransactionCreate stage with applicable type(s) Status for txn #8045 on ticket #60225 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:482)
[05:46:47]: Skipping Scrip #11 because it isn’t applicable (/opt/rt4/sbin/…/lib/RT/Scrips.pm:337)
[05:46:47]: Skipping Scrip #17 because it isn’t applicable (/opt/rt4/sbin/…/lib/RT/Scrips.pm:337)
[05:46:47]: Skipping Scrip #25 because it isn’t applicable (/opt/rt4/sbin/…/lib/RT/Scrips.pm:337)
[05:46:47]: About to commit scrips for transaction #8045 (/opt/rt4/sbin/…/lib/RT/Transaction.pm:212)
[05:46:47]: Committing scrip #13 on txn #8045 of ticket #60225 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:293)
[05:46:47]: About to prepare scrips for transaction #8046 (/opt/rt4/sbin/…/lib/RT/Transaction.pm:189)
[05:46:47]: Found 5 scrips for TransactionCreate stage with applicable type(s) Set for txn #8046 on ticket #60225 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:482)
[05:46:47]: Skipping Scrip #11 because it isn’t applicable (/opt/rt4/sbin/…/lib/RT/Scrips.pm:337)
[05:46:47]: Skipping Scrip #16 because it isn’t applicable (/opt/rt4/sbin/…/lib/RT/Scrips.pm:337)
[05:46:47]: Skipping Scrip #17 because it isn’t applicable (/opt/rt4/sbin/…/lib/RT/Scrips.pm:337)
[05:46:47]: About to commit scrips for transaction #8046 (/opt/rt4/sbin/…/lib/RT/Transaction.pm:212)
[05:46:47]: Committing scrip #13 on txn #8046 of ticket #60225 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:293)
[05:46:47]: Committing scrip #28 on txn #8046 of ticket #60225 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:293)
[05:46:47]: >>>> TRANSACTION TYPE: Set <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:28)
[05:46:47]: >>>> TRANSACTION FIELD: Queue <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:29)
[05:46:47]: >>>> TRANSACTION OLD VALUE: 7 <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:31)
[05:46:47]: >>>> TRANSACTION NEW VALUE: 5 <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:32)
[05:46:47]: >>>> TICKET QUEUE (new 5/8) <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:58)
[05:46:47]: >>>> cf T_Retriage Old: 1 <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:60)
[05:46:47]: >>>> cf T_Retriage New: 2 <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:63)
[05:46:47]: About to prepare scrips for transaction #8047 (/opt/rt4/sbin/…/lib/RT/Transaction.pm:189)
[05:46:47]: Found 2 scrips for TransactionCreate stage with applicable type(s) CustomField for txn #8047 on ticket #60225 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:482)
[05:46:47]: Skipping Scrip #11 because it isn’t applicable (/opt/rt4/sbin/…/lib/RT/Scrips.pm:337)
[05:46:47]: About to commit scrips for transaction #8047 (/opt/rt4/sbin/…/lib/RT/Transaction.pm:212)
[05:46:47]: Committing scrip #13 on txn #8047 of ticket #60225 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:293)
[05:46:47]: >>>> ret 1296 with msg T_Retriage 1 changed to 2 <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:65)
[05:46:47]: >>>> cf T_Retriage Now: 2 <<<< (/opt/rt4/sbin/…/local/lib/RT/Action/SetCFsQChange.pm:67)
[05:46:47]: About to prepare scrips for transaction #8048 (/opt/rt4/sbin/…/lib/RT/Transaction.pm:189)
[05:46:47]: Found 3 scrips for TransactionCreate stage with applicable type(s) Status for txn #8048 on ticket #60225 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:482)
[05:46:47]: Skipping Scrip #11 because it isn’t applicable (/opt/rt4/sbin/…/lib/RT/Scrips.pm:337)
[05:46:47]: Skipping Scrip #17 because it isn’t applicable (/opt/rt4/sbin/…/lib/RT/Scrips.pm:337)
[05:46:47]: About to commit scrips for transaction #8048 (/opt/rt4/sbin/…/lib/RT/Transaction.pm:212)
[05:46:47]: Committing scrip #13 on txn #8048 of ticket #60225 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:293)
[05:46:47]: Found 0 scrips for TransactionBatch stage with applicable type(s) Status for txn #8048 on ticket #60225 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:482)
[05:46:47]: About to prepare scrips for transaction #8049 (/opt/rt4/sbin/…/lib/RT/Transaction.pm:189)
[05:46:47]: Found 2 scrips for TransactionCreate stage with applicable type(s) CustomField for txn #8049 on ticket #60225 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:482)
[05:46:47]: Skipping Scrip #11 because it isn’t applicable (/opt/rt4/sbin/…/lib/RT/Scrips.pm:337)
[05:46:47]: About to commit scrips for transaction #8049 (/opt/rt4/sbin/…/lib/RT/Transaction.pm:212)
[05:46:47]: Committing scrip #13 on txn #8049 of ticket #60225 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:293)
[05:46:47]: Found 0 scrips for TransactionBatch stage with applicable type(s) Status,Set,CustomField for txn #8045 on ticket #60225 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:482)
[05:46:47]: Found 0 scrips for TransactionBatch stage with applicable type(s) CustomField for txn #8047 on ticket #60225 (/opt/rt4/sbin/…/lib/RT/Scrips.pm:482)

If you are running in batch mode you need to look at the TransactionBatch array which is an array of any transactions that have taken place