Template snippet causes template to silently fail

Hi all,
The way our company uses RT, there’s no need to distinguish between
comments and replies, and users may use either one without realizing the
difference. In my new email template, I want to show whichever was set. My
template works fine without the two if statements I’m trying to use, but as
soon as I put them in, it fails. The odd thing is that, though the email
using the template is never sent, I don’t get any errors at all. When I was
missing a dollar sign earlier, I got an error–an error not really related
to the dollar sign, but an error. Now, though, I get nothing whatsoever.
Here’s the snippet:

{ if (my $transactionCorrespond = $Transaction->correspond) {
$transactionCorrespond
} elsif (my $transactionComment = $Transaction->comment) {
$transactionComment }
}

I don’t know what’s so wrong with that bit of code, but there must be
something. I don’t really speak Perl, and the only page I’ve found thus far
that enumerates the Transaction object properties isn’t overly helpful, so
I’m guessing at the properties I need. Can anyone see what I’ve done wrong
here? Thanks.

Alex Hall
Automatic Distributors, IT department
ahall@autodist.com

Hey Alex,

Hi all,
The way our company uses RT, there’s no need to distinguish between comments
and replies, and users may use either one without realizing the difference.
In my new email template, I want to show whichever was set. My template
works fine without the two if statements I’m trying to use, but as soon as I
put them in, it fails. The odd thing is that, though the email using the
template is never sent, I don’t get any errors at all. When I was missing a
dollar sign earlier, I got an error–an error not really related to the
dollar sign, but an error. Now, though, I get nothing whatsoever. Here’s the
snippet:

You can see some documentation regarding txns at:

https://docs.bestpractical.com/rt/4.4.1/RT/Transaction.html

{ if (my $transactionCorrespond = $Transaction->correspond) {
$transactionCorrespond
} elsif (my $transactionComment = $Transaction->comment) {
$transactionComment }
}

Here is some untested code…

my $type = $Transaction->Type;

$type now holds “Correspond” or “Comment”

if ($type eq ‘Correspond’) {
# do something for correspond
}
elsif ($type eq ‘Comment’) {
# do something for comment
}
else {
# Perhaps this txn is a Create…
}

-m

Hi all,
The way our company uses RT, there’s no need to distinguish between comments and replies, and users may use either one without realizing the difference. In my new email template, I want to show whichever was set. My template works fine without the two if statements I’m trying to use, but as soon as I put them in, it fails. The odd thing is that, though the email using the template is never sent, I don’t get any errors at all. When I was missing a dollar sign earlier, I got an error–an error not really related to the dollar sign, but an error. Now, though, I get nothing whatsoever. Here’s the snippet:

{ if (my $transactionCorrespond = $Transaction->correspond) { $transactionCorrespond
} elsif (my $transactionComment = $Transaction->comment) { $transactionComment }
}

I don’t know what’s so wrong with that bit of code, but there must be something. I don’t really speak Perl, and the only page I’ve found thus far that enumerates the Transaction object properties isn’t overly helpful, so I’m guessing at the properties I need. Can anyone see what I’ve done wrong here? Thanks.

Since $Transaction is a thing then $Transaction->correspond is empty since it’s not a thing. This is why you’ll get no errors.

Try this:
{
if ($self->TransactionObj->Type eq ‘Correspond’) {
# something
} elsif ($self->TransactionObj->Type eq ‘Comment’) {
# something else
} else {
# Not a Comment or Correspond transaction
}
}

Or something that actually does exactly what your pseudocode does:
{ $self->TransactionObj->Type }

I have found these very helpful in the past:
https://rt-wiki.bestpractical.com/wiki/CustomConditionSnippets

Landon Stewart
Lead Analyst - Abuse and Security Management
INTERNAP ®
:e-mail: lstewart@internap.commailto:lstewart@internap.com
:earth_africa: www.internap.comhttp://www.internap.com

Thanks for the suggestions, but I’m still seeing the same exact problem. If
I put the code in, the email based on this template fails to send. The log,
however, remains absent any error or warning messages around the time of
each attempt I make. I’ll paste my latest try below, but note that I’ve
tried $Transaction in place of $self->TransactionObj and gotten the same
result.

Content: { my $transactionType = $self->TransactionObj->Type; if ($transactionType eq 'Correspond') { $self->TransactionObj->Correspond } elsif ($transactionType eq 'Comment') { $self->TransactionObj->Comment } else { "No content to display." } }

On Wed, Oct 26, 2016 at 7:52 PM, Landon Stewart wrote:

On Oct 26, 2016, at 2:29 PM, Alex Hall ahall@autodist.com wrote:

Hi all,
The way our company uses RT, there’s no need to distinguish between
comments and replies, and users may use either one without realizing the
difference. In my new email template, I want to show whichever was set. My
template works fine without the two if statements I’m trying to use, but as
soon as I put them in, it fails. The odd thing is that, though the email
using the template is never sent, I don’t get any errors at all. When I was
missing a dollar sign earlier, I got an error–an error not really related
to the dollar sign, but an error. Now, though, I get nothing whatsoever.
Here’s the snippet:

{ if (my $transactionCorrespond = $Transaction->correspond) {
$transactionCorrespond
} elsif (my $transactionComment = $Transaction->comment) {
$transactionComment }
}

I don’t know what’s so wrong with that bit of code, but there must be
something. I don’t really speak Perl, and the only page I’ve found thus far
that enumerates the Transaction object properties isn’t overly helpful, so
I’m guessing at the properties I need. Can anyone see what I’ve done wrong
here? Thanks.

Since $Transaction is a thing then $Transaction->correspond is empty since
it’s not a thing. This is why you’ll get no errors.

Try this:
{
if ($self->TransactionObj->Type eq ‘Correspond’) {
# something
} elsif ($self->TransactionObj->Type eq ‘Comment’) {
# something else
} else {
# Not a Comment or Correspond transaction
}
}

Or something that actually does exactly what your pseudocode does:
{ $self->TransactionObj->Type }

I have found these very helpful in the past:
CustomConditionSnippets - Request Tracker Wiki


Landon Stewart
Lead Analyst - Abuse and Security Management
INTERNAP ®
:e-mail: lstewart@internap.com
:earth_africa: www.internap.com

Alex Hall
Automatic Distributors, IT department
ahall@autodist.com