Template not seeing value just set in Scrip

I must be missing something obvious…

On Create, I have a Scrip that looks at the requestor’s Organization field
(presuming, of course, they’ve sent us email before and we’ve set a value
for it). If it matches one of the values in a multi-select custom field we
have at the Ticket level called “Client”, then it automatically assigns the
“Client” custom field to that ticket. Here is the relevant part from that
Scrip:

my $T_Obj = $self->TicketObj;

$T_Obj->AddCustomFieldValue( Field => “Client”, Value => $client->Name );

That works great. Next, it goes to another Scrip that then performs a
Notify AdminCcs using a custom template. This template sends the AdminCcs a
copy of the Transaction->Content, but then appends the just assigned custom
field to the email. Here is the relevant part from that Template:

{$Transaction->Content()}

{ my $OUTPUT;

my $rTicket = RT::Ticket->new( $RT::SystemUser );

$rTicket->Load($Ticket->id);

my $values = $rTicket->CustomFieldValues(‘Client’);

$OUTPUT .= “:” . $values . “:
”;

while (my $value = $values->Next ) {

 $OUTPUT .= "*" . $value->Content . "*<BR>";

}

$OUTPUT;

}

Now, here’s the problem. If that custom field was propagated via the Scrip
mentioned in the first section, it doesn’t carry that value into the
Template even though the Template is executed after it:

Execution Order (reversed):

Wed Mar 30 14:39:21 2011 The RT System itself - Outgoing email recorded
[Show]

Wed Mar 30 14:39:20 2011 The RT System itself - Outgoing email recorded
[Show]

Wed Mar 30 14:39:18 2011 The RT System itself - Client AAAA added

If, however, I use RT to create a new ticket and self-select the Client
custom field, it will work. So, I know I’m pulling the right field out in
the Template.

I even tried re-loading the ticket (as you see above) in the hopes that it
would re-read the new value from the database.

Any idea how I might be able to accomplish this? As far as I can tell, the
Scrip is correctly updating the DB, it executes before the Template gets
rendered, and the code is correct in the Template. Thanks.

–drew

Drew,

Absolutely. We had the same problem awhile back. We changed the “Stage” to
TransactionBatch for any scrip that update a field (CF or otherwise) and for
scrips that notify using templates that show those fields. Works great.

Kenn
LBNLOn Wed, Mar 30, 2011 at 11:52 AM, Drew Hahn dhahn@newsroomsolutions.comwrote:

I must be missing something obvious…

On Create, I have a Scrip that looks at the requestor’s Organization field
(presuming, of course, they’ve sent us email before and we’ve set a value
for it). If it matches one of the values in a multi-select custom field we
have at the Ticket level called “Client”, then it automatically assigns the
“Client” custom field to that ticket. Here is the relevant part from that
Scrip:

my $T_Obj = $self->TicketObj;

$T_Obj->AddCustomFieldValue( Field => “Client”, Value => $client->Name );

That works great. Next, it goes to another Scrip that then performs a
Notify AdminCcs using a custom template. This template sends the AdminCcs a
copy of the Transaction->Content, but then appends the just assigned custom
field to the email. Here is the relevant part from that Template:

{$Transaction->Content()}

{ my $OUTPUT;

my $rTicket = RT::Ticket->new( $RT::SystemUser );

$rTicket->Load($Ticket->id);

my $values = $rTicket->CustomFieldValues(‘Client’);

$OUTPUT .= “:” . $values . “:
”;

while (my $value = $values->Next ) {

 $OUTPUT .= "*" . $value->Content . "*<BR>";

}

$OUTPUT;

}

Now, here’s the problem. If that custom field was propagated via the Scrip
mentioned in the first section, it doesn’t carry that value into the
Template even though the Template is executed after it:

Execution Order (reversed):

Wed Mar 30 14:39:21 2011 The RT System itself - Outgoing email recorded
[Show]

Wed Mar 30 14:39:20 2011 The RT System itself - Outgoing email recorded
[Show]

Wed Mar 30 14:39:18 2011 The RT System itself - Client AAAA added

If, however, I use RT to create a new ticket and self-select the Client
custom field, it will work. So, I know I’m pulling the right field out in
the Template.

I even tried re-loading the ticket (as you see above) in the hopes that it
would re-read the new value from the database.

Any idea how I might be able to accomplish this? As far as I can tell, the
Scrip is correctly updating the DB, it executes before the Template gets
rendered, and the code is correct in the Template. Thanks.

–drew

Drew,

Did you turn on TransactionBatch (Set($UseTransactionBatch, ‘1’); ) in
your RT_SiteConfig.pm file?

Kenn
LBNLOn Wed, Mar 30, 2011 at 5:26 PM, Drew Hahn dhahn@newsroomsolutions.comwrote:

Kenn,

Thanks for the suggestion, but that didn’t seem to do it. I set both the
Scrip that sets the CF field and the one that fires the Template to
TransactionBatch. But same thing – the second Scrip doesn’t see the change.

–drew

From: rt-users-bounces@lists.bestpractical.com [mailto:
rt-users-bounces@lists.bestpractical.com] *On Behalf Of *Kenneth Crocker
Sent: Wednesday, March 30, 2011 7:51 PM
To: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Template not seeing value just set in Scrip

Drew,

Absolutely. We had the same problem awhile back. We changed the “Stage” to
TransactionBatch for any scrip that update a field (CF or otherwise) and for
scrips that notify using templates that show those fields. Works great.

Kenn
LBNL