Can Templates be Conditionalized Based on Recipient Address?

Hi,

We’re running rt 3.8.4.

We have one particular queue for which we conditionalize the email sent out
based on the creator of the transaction generating the email. We do this by
checking $Transaction->CreatorObj->Name in the template.

We’d also like to further customize the email based on who the email is going
to. More precisely, we want the copy of the email going to the requestor to
say something slightly different to the copy going to the queue watchers.

I’ve experimented with several approaches, but haven’t managed to get this
working.

I thought if I could get the ScripAction name I could include a test against
"Notify Owner", etc. I tried getting that via
$Transaction->Scrips->First->ScripActionObj->Name, but the actions I got
back were not ones that were associated with this template.

I then tried getting the addresses associated with the current transaction
using $Transaction->Addresses, but that seemed to return empty lists
(though I could easily have been doing something wrong).

I could go into more detail regarding the above but in the interests of
keeping this email from getting any longer I won’t. I wasn’t particularly
happy about either approach anyway, so before spending more time debugging
them, I thought I’d ask if anyone knew whether it was possible to
conditionalize templates in this way and if so, how.

While I’ve been writing this, it occurred to me that the easiest way to
achieve what I want might be to set up different templates for the different
scrips. But because the templates are mostly identical I’d rather not have
that duplication if it is avoidable.

Thanks for any advice,

Duncan

http://wiki.bestpractical.com/view/ForkTemplate

Cambridge Energy Alliance: Save money. Save the planet.

Hi Jerrad,Jerrad Pierce jpierce@cambridgeenergyalliance.org wrote:

http://wiki.bestpractical.com/view/ForkTemplate

That looks interesting, though I’m not immediately sure how it solves my
problem. I need to customise the template based on the recipient rather
than on the value of a custom field.

Once I’d figured out who the recipient was, I was planning on customising
the template text using a simple "if () {…} statement (though admittedly,
ForkTemplate may well be a nicer way of doing that). But as described in my
original post, I tried two ways of finding out who the recipients of a
transaction were and couldn’t get either to work.

Thanks for the pointer to ForkTemplate though. It may come in useful
sometime…

Duncan

That looks interesting, though I’m not immediately sure how it solves my
problem. I need to customise the template based on the recipient rather
than on the value of a custom field.
It’s just a test, you can use whatever you want as the condition.

Once I’d figured out who the recipient was, I was planning on customising
the template text using a simple "if () {…} statement (though admittedly,
ForkTemplate may well be a nicer way of doing that). But as described in my
original post, I tried two ways of finding out who the recipients of a
transaction were and couldn’t get either to work.
Because it’s a PITA due to one-time CC’s and the like.
Take a look at share/html/Ticket/Elements/PreviewScrips to get an idea
of how it can be done.