[rt-users] Set Custom field in template

Jon Witts jwitts at queenmargarets.com
Tue Mar 4 11:01:21 EST 2014


Looking further into this... 

When we run:

rt-crontool --search RT::Search::FromSQL --search-arg "Queue = 'Estate'" --action RT::Action::Notify --action-arg 'All' --template 'Auto-Close Warning HTML' --transaction last --verbose

The template is only setting the custom field on the first ticket in the search; but also the notification emails for all tickets in the search are not getting their ticket object, they are using the ticket object from the first returned ticket in the search. 

i.e.  The template code is this:

Subject: Auto-Close Warning: {$Ticket->Subject}
Content-Type: text/html

<!--{$Ticket->AddCustomFieldValue(Field => 'Auto-Close Reminder', Value => 'TRUE', RecordTransaction => 1 );}-->

<p>Hello,</p>

<p>This message has been automatically generated to let you know that your  support request regarding "<b>{$Ticket->Subject()}</b>",
has been in a "stalled" state awaiting further information from yourself for a week. This ticket was assigned an ID of "<b>{$Ticket->SubjectTag}</b>".</p>

and we have 4 tickets returned by our search. Every ticket has a notification email sent but the $Ticket->Subject variable for all notifications on all 4 tickets is the value of the first tickets subject... I guess this explains why only the first ticket is having its custom field updated, but how do we use rt-crontool to update multiple tickets and send out emails?

Thanks,
Jon
-----------------------------------------------------

Jon Witts
Director of Digital Strategy
Queen Margaret's School
Escrick Park
York YO19 6EU

Telephone: 01904 727600
Fax: 01904 728150

Website: www.queenmargarets.com 


-----Original Message-----
From: rt-users-bounces at lists.bestpractical.com [mailto:rt-users-bounces at lists.bestpractical.com] On Behalf Of Jon Witts
Sent: 04 March 2014 15:49
To: rt-users at lists.bestpractical.com
Subject: Re: [rt-users] Set Custom field in template

Hi Jim,

I have edited my template code to this:

Subject: Auto-Close Warning: {$Ticket->Subject}
Content-Type: text/html

<!--{$Ticket->AddCustomFieldValue(Field => 'Auto-Close Reminder', Value => 'TRUE', RecordTransaction => 1 );}-->

<p>Hello,</p>

<p>This message has been automatically generated to let you know that your  support request regarding "<b>{$Ticket->Subject()}</b>", has been in a "stalled" state awaiting further information from yourself for a week. This ticket was assigned an ID of "<b>{$Ticket->SubjectTag}</b>".</p>

Which now works; but only when the search from rt-crontool returns just one ticket. If the search returns more than one ticket then only the first ticket has it's CF changed, all others remain the same. The email is sent for the other tickets however...

What do I need to do so that the template runs this setting CF code for each ticket in the search?

Many thanks,
Jon

-----------------------------------------------------

Jon Witts
Director of Digital Strategy
Queen Margaret's School
Escrick Park
York YO19 6EU

Telephone: 01904 727600
Fax: 01904 728150

Website: www.queenmargarets.com 

----------------------------------------

On 3/4/14 6:13 AM, Jon Witts wrote:
> and the contents of the template "Auto-Close Warning HTML" is as follows:
>
> --------------------------------------
>
> my $CFName = 'Auto-Close Reminder';
> my $DefaultValue = 'TRUE';
>
> unless( $self->Ticket->FirstCustomFieldValue( $CFName ) eq $DefaultValue ) {
> 		my( $st, $msg ) = $self->Ticket->AddCustomFieldValue(
> 					Field => $CFName,
>                                          Value => $DefaultValue,
>                                          RecordTransaction => 1 );
> 	}
>
> Subject: Auto-Close Warning: {$Ticket->Subject}

I think your issue is after the 'unless' where you're calling Ticket on $self. In templates the ticket object is available as just $Ticket as in the Subject line above. Try switching your $self->Ticket to $Ticket anywhere you're calling $self in the template.

More docs on templates are available here:

http://bestpractical.com/docs/rt/latest/customizing/templates.html

You'll also need to put that initial code in some curly braces { } inside the template. More info here:

https://metacpan.org/pod/Text::Template

--



This email has been processed by Smoothwall Anti-Spam - www.smoothwall.net

--
RT Training London, March 19-20 and Dallas May 20-21 http://bestpractical.com/training


This email has been processed by Smoothwall Anti-Spam - www.smoothwall.net




More information about the rt-users mailing list