[rt-users] Back to my Dynamic template choosing Scrip problem...
Ruslan Zakirov
ruz at bestpractical.com
Thu Oct 3 07:27:27 EDT 2013
Hi,
You can do this by inserting custom TemplateObj method into
RT/Action/SendMail.pm
It should be like this:
1) behave like original method, so copy it from lib/RT/Action.pm
2) change template on call when Ticket and Txn are available
3) mark that change was done
For example:
sub TemplateObj {
my $self = shift;
return $self->{TemplateObj} if !$self->{TemplateObj}
|| $self->{our_custom_code_has_made_the_change};
my $ticket = $self->TicketObj;
return $self->{TemplateObj} unless $ticket;
my $orig_name = $self->{TemplateObj}->Name;
my $lang = $ticket->FirstCustomFieldValue('Language');
my $case_type = $ticket->FirstCustomFieldValue('Category');
foreach my $name ("$orig_name $case_type $lang", "$orig_name $case_type
$lang") {
my $tmp = RT::Template->new( $self->CurrentUser );
$tmp->Load( $name ); # queue should be here and fallback to global!
unless ($tmp->id) {
RT->Logger->debug("No custom template $name");
} else {
$self->{TemplateObj} = $tmp;
}
}
$self->{our_custom_code_has_made_the_change} = 1;
return $self->{TemplateObj};
}
Note that the code is not tested in any way, just typed it in mail client.
On Thu, Oct 3, 2013 at 12:59 AM, Landon Stewart <lstewart at iweb.com> wrote:
> Hello,
>
> This is not an easy issue to work out - I'm sorry for repeating this
> question but last time I answered myself and then realized the answer
> wasn't going to work out. Anyway here goes...
>
> I have a CF called "Classification" where we classify a ticket based on a
> scoring system for keywords in fields like From:, Subject: and Content of
> an incoming email report. The incident report might be classified as one
> of "Phishing", "Open Recursive DNS" or "Malware" etc. There are currently
> 12 different classifications and more may need to be added. When opening
> an Investigation for an issue the CF "Classification" is used to determine
> the template to send to the client containing some helpful information and
> what is required of them.
>
> Not only are we dealing with multiple templates but also each one has its
> own language. English, French and Spanish. It is very cumbersome to have
> 3 Scrips for each classification.
>
> *Below is 1 example for the "Open Recursive DNS" classification in all
> three languages and how it is dealt with currently:*
>
> *Desc:* On Create Customer Open Recursive DNS English
> *Condition:* User Defined
> *Action:* Autoreply To Requestor
> *Template:* Open Recursive DNS (en)
> *Stage:* TransactionCreate
> *Custom Condition:*
> my $trans = $self->TransactionObj;
> my $ticket = $self->TicketObj;
> return 0 unless $trans->Type eq "Create";
> return 0 unless $ticket->FirstCustomFieldValue('Classification') eq "Open
> Recursive DNS";
> ## If English or no language choose English below...
> if ($ticket->FirstCustomFieldValue('PreferredLanguage') eq 'English' ||
> $ticket->FirstCustomFieldValue('PreferredLanguage') eq "") {
>
> return 1;
> }
>
> *Desc:* On Create Customer Open Recursive DNS French
> *Condition:* User Defined
> *Action:* Autoreply To Requestor
> *Template:* Open Recursive DNS (fr)
> *Stage:* TransactionCreate
> *Custom Condition:*
> my $trans = $self->TransactionObj;
> my $ticket = $self->TicketObj;
> return 0 unless $trans->Type eq "Create";
> return 0 unless $ticket->FirstCustomFieldValue('Classification') eq "Open
> Recursive DNS";
> if ($ticket->FirstCustomFieldValue('PreferredLanguage') eq 'French') {
> return 1;
> }
>
> *Desc:* On Create Customer Open Recursive DNS Spanish
> *Condition:* User Defined
> *Action:* Autoreply To Requestor
> *Template:* Open Recursive DNS (es)
> *Stage:* TransactionCreate
> *Custom Condition:*
> my $trans = $self->TransactionObj;
> my $ticket = $self->TicketObj;
> return 0 unless $trans->Type eq "Create";
> return 0 unless $ticket->FirstCustomFieldValue('Classification') eq "Open
> Recursive DNS";
> if ($ticket->FirstCustomFieldValue('PreferredLanguage') eq 'Spanish') {
> return 1;
> }
>
> "OK!? So what's the problem?" you might ask…
>
> Can anyone tell me how to roll this into one Scrip without making the
> templates themselves a mess of spaghetti code?
>
> *Pseudo code might be:*
> *Desc:* On Create Customer Open Recursive DNS
> *Condition:* User Defined
> *Action:* Autoreply To Requestor
> *Template:* Global template: Blank
> *Stage:* TransactionCreate
> *Fake Code Custom Condition:*
> my $trans = $self->TransactionObj;
> my $ticket = $self->TicketObj;
> return 0 unless $trans->Type eq "Create";
> my $class = $self->FirstCustomFieldValue('Classification');
> my $lang = $ticket->FirstCustomFieldValue('PreferredLanguage');
> my $template = $class." (".$lang.")";
> ## Eg: Open Recursive DNS (French)
> if (SetTheTemplateTo($template)) {
> return 1;
> }
> return 0;
>
> I know SetTheTemplateTo() is not a real function… But that's what I want
> to work out how to do. Basically override or supplement the template set
> on the Scrip form.
>
>
> --
> Landon Stewart :: lstewart at iweb.com
> Lead Specialist, Abuse and Security Management
> Spécialiste principal, gestion des abus et sécurité
> http://iweb.com :: +1 (888) 909-4932
>
>
>
>
> --
> RT Training in New York, October 8th and 9th:
> http://bestpractical.com/training
>
--
Best regards, Ruslan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20131003/a458ba4d/attachment.htm>
More information about the rt-users
mailing list