Set Custom field in template

Hi all,

I am trying to use a template to set a ticket custom field so that we can configure RT to send out reminders when a ticket has been stalled for a week. We are running RT 4.2.0

The command I am passing to rt-crontool is as follows:

rt-crontool --search RT::Search::FromSQL --search-arg “Queue = ‘Estate’ AND Subject LIKE ‘email’” --action RT::Action::Notify --action-arg ‘All’ --template ‘Auto-Close Warning HTML’ --verbose

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 );
}

Content-Type: text/html

Hello,

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

If you do not respond with the requested information within 7 days then we will assume that this support request is no longer required and automatically close this request.

You may reply to this message to provide us with the required information, or you can visit the helpdesk to see all of your current support requests here:

Thank you,
{$Ticket->QueueObj->CorrespondAddress()}

This is giving me the following error:

[error]: Template parsing error: Can’t call method “Ticket” on an undefined value at template line 5. (/opt/rt4/bin/…/lib/RT/Template.pm:542)

My Perl is very basic (to say the least!) and I have pulled this code together from searching around. Could anyone on the list highlight where I am going wrong?

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

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

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:

Hi Jim,

I have edited my template code to this:

Content-Type: text/html

Hello,

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

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.comOn 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:

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

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

Hello,

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

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

From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Jon Witts
Sent: 04 March 2014 15:49
To: rt-users@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

Hello,

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

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

When running this using the built-in Auto Reply template we are seeing the same issue:

rt-crontool --search RT::Search::FromSQL --search-arg “Queue = ‘Estate’ AND ‘CF.{Auto-Close Reminder}’ NOT LIKE ‘TRUE’” --action RT::Action::Notify --action-arg ‘All’ --template ‘Autoreply in HTML’ --transaction last --verbose

Is this a bug with how rt-crontool is running or is there something fundamentally wrong with my rt-crontool command?

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.comFrom: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Jon Witts
Sent: 04 March 2014 16:01
To: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Set Custom field in template

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

Hello,

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

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

From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Jon Witts
Sent: 04 March 2014 15:49
To: rt-users@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

Hello,

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

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

So I decided to leave this alone yesterday and have a look again with fresh eyes this morning…

Changing our rt-crontool command to this:

rt-crontool --search RT::Search::FromSQL --search-arg “Queue = ‘Estate’” --action RT::Action::RecordCorrespondence --template ‘Auto-Close Warning HTML’ --transaction last --verbose --log debug

produces the expected results.

Can anyone explain why using the action RT::Action::Notify would produce the effect of only using the first ticket variables when it runs through the template?

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.comFrom: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Jon Witts
Sent: 04 March 2014 16:24
To: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Set Custom field in template

When running this using the built-in Auto Reply template we are seeing the same issue:

rt-crontool --search RT::Search::FromSQL --search-arg “Queue = ‘Estate’ AND ‘CF.{Auto-Close Reminder}’ NOT LIKE ‘TRUE’” --action RT::Action::Notify --action-arg ‘All’ --template ‘Autoreply in HTML’ --transaction last --verbose

Is this a bug with how rt-crontool is running or is there something fundamentally wrong with my rt-crontool command?

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

From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Jon Witts
Sent: 04 March 2014 16:01
To: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Set Custom field in template

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

Hello,

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

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

From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Jon Witts
Sent: 04 March 2014 15:49
To: rt-users@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

Hello,

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

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

I have logged this as a bug over here: http://issues.bestpractical.com/Ticket/Display.html?id=29454

For now I am having to use a combination of the RT::Action::RecordCorrespondence action and then running another cron job immediately afterwards to switch the status of those tickets back to stalled…

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.comFrom: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Jon Witts
Sent: 05 March 2014 09:14
To: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Set Custom field in template

So I decided to leave this alone yesterday and have a look again with fresh eyes this morning…

Changing our rt-crontool command to this:

rt-crontool --search RT::Search::FromSQL --search-arg “Queue = ‘Estate’” --action RT::Action::RecordCorrespondence --template ‘Auto-Close Warning HTML’ --transaction last --verbose --log debug

produces the expected results.

Can anyone explain why using the action RT::Action::Notify would produce the effect of only using the first ticket variables when it runs through the template?

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

From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Jon Witts
Sent: 04 March 2014 16:24
To: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Set Custom field in template

When running this using the built-in Auto Reply template we are seeing the same issue:

rt-crontool --search RT::Search::FromSQL --search-arg “Queue = ‘Estate’ AND ‘CF.{Auto-Close Reminder}’ NOT LIKE ‘TRUE’” --action RT::Action::Notify --action-arg ‘All’ --template ‘Autoreply in HTML’ --transaction last --verbose

Is this a bug with how rt-crontool is running or is there something fundamentally wrong with my rt-crontool command?

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

From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Jon Witts
Sent: 04 March 2014 16:01
To: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Set Custom field in template

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

Hello,

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

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

From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Jon Witts
Sent: 04 March 2014 15:49
To: rt-users@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

Hello,

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

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