Issue with a Scrip to keep the date of a Owner Changed

Hello,

I try to keep the date of a Owner changed event.

To do this, I use a scrip to write this date value in a CustomField named
"LastOwnerChangeDate".

Condition: “On Owner Change”

Action: “User Defined”

Template: “Global Template: Blank”

Stage: “TransactionCreate”

Custom condition:

return 1;

Custom action preparation code:

my $trans = $self->TransactionObj;

my $ticket = $self->TicketObj;

my $cf_obj = RT::CustomField->new($RT::SystemUser);

my $cf_name = “LastOwnerChangeDate”;

my $cf_value = $trans->CreatedAsString;

$cf_obj->LoadByName(Name=>$cf_name);

$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n”);

$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$cf_value,
RecordTransaction=>0);

return 1;

Custom action cleanup code:

return 1;

It is almost working… :

  • When I steal a ticket it works.

  • When I give a ticket from the “People” section it works.

  • When I give a ticket from the “Basics” or “Jumbo” section, the date is
    not changed… And here is my issue!

In fact, I think that RT begin by evaluating that the owner is changed so
the CustomField “LastOwnerChangeDate” is replaced to the new value by the
scrip (OK, that’s good!).

But then RT evaluates the Field “LastOwnerChangeDate” in the web form… RT
see the old value in the field (the new one is already in the DB) and
replace the new value by the old one…

Maybe I’m wrong but this is what I understand from the logs.

Logs for “Steal” or “Give” in the “People” section:

Jun 6 13:37:06 rt-support RT: About to think about scrips for transaction
#112

Jun 6 13:37:06 rt-support RT: About to prepare scrips for transaction #112

Jun 6 13:37:06 rt-support RT: Found 1 scrips for TransactionCreate stage
with applicable type(s) Steal

Jun 6 13:37:06 rt-support RT: Loaded$cf_obj->Name = LastOwnerChangeDate

Jun 6 13:37:06 rt-support RT: About to commit scrips for transaction #112

Jun 6 13:37:06 rt-support RT: Committing scrip #12 on txn #112 of ticket #1

Jun 6 13:37:06 rt-support RT: Found 0 scrips for TransactionBatch stage
with applicable type(s) Steal

Logs for “Give” in the “Basics” or “Jumbo” section:

Jun 6 13:36:45 rt-support RT: About to think about scrips for transaction
#110

Jun 6 13:36:45 rt-support RT: About to prepare scrips for transaction #110

Jun 6 13:36:45 rt-support RT: Found 1 scrips for TransactionCreate stage
with applicable type(s) Give

Jun 6 13:36:45 rt-support RT: Loaded$cf_obj->Name = LastOwnerChangeDate

Jun 6 13:36:45 rt-support RT: About to commit scrips for transaction #110

Jun 6 13:36:45 rt-support RT: Committing scrip #12 on txn #110 of ticket #1

Jun 6 13:36:45 rt-support RT: About to think about scrips for transaction
#111

Jun 6 13:36:45 rt-support RT: About to prepare scrips for transaction #111

Jun 6 13:36:45 rt-support RT: Found 1 scrips for TransactionCreate stage
with applicable type(s) CustomField

Jun 6 13:36:45 rt-support RT: About to commit scrips for transaction #111

Jun 6 13:36:45 rt-support RT: Found 0 scrips for TransactionBatch stage
with applicable type(s) Give,CustomField

How can I make it works without this issue ?

Thanks.

Sebastien,

Try using the stage "TransactionBatch" (remember to turn it on in 

RT_SiteConfig.pm). I think that will do it. Also, I don’t think you need
the “return 1;” on the Custom Condition code area as you have already
set a condition by selecting one that is NOT user-defined. Hope this helps.

Kenn
LBNLOn 6/8/2009 2:06 AM, S�bastien Mesnard wrote:

Hello,

I try to keep the date of a Owner changed event.

To do this, I use a scrip to write this date value in a CustomField
named “LastOwnerChangeDate”.

Condition: “On Owner Change”

Action: “User Defined”

Template: “Global Template: Blank”

Stage: “TransactionCreate”

Custom condition:

return 1;

Custom action preparation code:

my $trans = $self->TransactionObj;

my $ticket = $self->TicketObj;

my $cf_obj = RT::CustomField->new($RT::SystemUser);

my $cf_name = “LastOwnerChangeDate”;

my $cf_value = $trans->CreatedAsString;

$cf_obj->LoadByName(Name=>$cf_name);

$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n”);

$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$cf_value,
RecordTransaction=>0);

return 1;

Custom action cleanup code:

return 1;

It is almost working… :

  • When I steal a ticket it works.

  • When I give a ticket from the “People” section it works.

  • When I give a ticket from the “Basics” or “Jumbo” section, the date
    is not changed… And here is my issue!

In fact, I think that RT begin by evaluating that the owner is changed
so the CustomField “LastOwnerChangeDate” is replaced to the new value
by the scrip (OK, that’s good!).

But then RT evaluates the Field “LastOwnerChangeDate” in the web
form… RT see the old value in the field (the new one is already in
the DB) and replace the new value by the old one…

Maybe I’m wrong but this is what I understand from the logs.

Logs for “Steal” or “Give” in the “People” section:

Jun 6 13:37:06 rt-support RT: About to think about scrips for
transaction #112

Jun 6 13:37:06 rt-support RT: About to prepare scrips for transaction
#112

Jun 6 13:37:06 rt-support RT: Found 1 scrips for TransactionCreate
stage with applicable type(s) Steal

Jun 6 13:37:06 rt-support RT: Loaded$cf_obj->Name = LastOwnerChangeDate

Jun 6 13:37:06 rt-support RT: About to commit scrips for transaction #112

Jun 6 13:37:06 rt-support RT: Committing scrip #12 on txn #112 of
ticket #1

Jun 6 13:37:06 rt-support RT: Found 0 scrips for TransactionBatch
stage with applicable type(s) Steal

Logs for “Give” in the “Basics” or “Jumbo” section:

Jun 6 13:36:45 rt-support RT: About to think about scrips for
transaction #110

Jun 6 13:36:45 rt-support RT: About to prepare scrips for transaction
#110

Jun 6 13:36:45 rt-support RT: Found 1 scrips for TransactionCreate
stage with applicable type(s) Give

Jun 6 13:36:45 rt-support RT: Loaded$cf_obj->Name = LastOwnerChangeDate

Jun 6 13:36:45 rt-support RT: About to commit scrips for transaction #110

Jun 6 13:36:45 rt-support RT: Committing scrip #12 on txn #110 of
ticket #1

Jun 6 13:36:45 rt-support RT: About to think about scrips for
transaction #111

Jun 6 13:36:45 rt-support RT: About to prepare scrips for transaction
#111

Jun 6 13:36:45 rt-support RT: Found 1 scrips for TransactionCreate
stage with applicable type(s) CustomField

Jun 6 13:36:45 rt-support RT: About to commit scrips for transaction #111

Jun 6 13:36:45 rt-support RT: Found 0 scrips for TransactionBatch
stage with applicable type(s) Give,CustomField

How can I make it works without this issue ?

Thanks.



http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

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

Thanks Ken,
It really helps.