[rt-users] Templates and custom ScripActions
Francis L Fabrizio
fabrizio at uab.edu
Fri Oct 22 13:06:00 EDT 2010
Gene,
I wouldn't mind embedding the logic in the template, in fact I tried that at first, but my decision making requires that I have access to $self->TransactionObj->NewValue from my CustomField. I couldn't seem to get at this from the template itself. I had trouble finding the right magic to access the Transaction's NewValue.
I've seen code samples that use $Transaction within templates, but $Transaction->NewValue seems undef. Are you aware of how I could get at NewValue?
Or perhaps as an alternative, a way to populate a variable in the Custom Condition that would then be accessible from the Template? I'm sort of grasping at straws, but hoping that somehow I can get the Template to see the NewValue of my CustomField. Once I have that, I can retrieve the email listing of users from the appropriate RT group and the rest is easy, and I would not need any user-defined action at that point.
Thanks,
Fran
> -----Original Message-----
> From: rt-users-bounces at lists.bestpractical.com [mailto:rt-users-
> bounces at lists.bestpractical.com] On Behalf Of Gene LeDuc
> Sent: Friday, October 22, 2010 11:34 AM
> To: rt-users at lists.bestpractical.com
> Subject: Re: [rt-users] Templates and custom ScripActions
>
> Hi Fran,
>
> On 10/22/2010 8:15 AM, Francis L Fabrizio wrote:
> > Do I have to do something specific when creating a Scrip and using
> Action: User Defined in order to get RT to process the associated
> template with the scrip?
> >
> > I have created a custom scrip, and just for testing purposes, I made
> the custom condition, custom action prep, and custom action cleanup all
> set to "return 1;", and associated my desired template with the scrip.
> The scrip fires and returns successfully, but the template is never
> touched.
> >
> > Are there specific steps I need to take in my custom action code in
> order to load, parse, and send notifications from a template?
> >
> > Thanks,
> > Fran
>
> I'm using v3.6.3, so this may not be accurate with your setup.
>
> I know of ways to do what you want.
>
> The way I prefer to do it is to embed the code into the template. I've
> found this to be fairly easy to do and it involves less code. It can
> also be trickier to debug because the scrip doesn't tell you what
> action
> is being taken - it's all in the template. It does make the template
> bigger. Almost all of my templates have embedded decision-making and
> data-processing routines in them. Here's a piece of one of my
> templates
> that builds a custom acknowledgment e-mail.
>
> ===== BEGIN TEMPLATE CODE
> { ### Tells user that ticket has been resolved
> my $FromAddress = 'DNS Requests <someaddress at domain>';
> my $ContactAddress = 'me at domain';
> my $OwnerName = $Ticket->OwnerObj->RealName;
> my $have_rmks;
> my $c_content;
>
> ### Get last Correspond
> my $Transactions = $Ticket->Transactions;
> $Transactions->Limit( FIELD => 'Type', VALUE => 'Correspond' );
> $Transactions->OrderByCols (
> { FIELD => 'Created', ORDER => 'DESC' },
> { FIELD => 'id', ORDER => 'DESC' },
> );
> my $CorrespondObj = $Transactions->First;
> if ($CorrespondObj && $CorrespondObj->Id) {
> $c_content = $CorrespondObj->Content;
> chomp $c_content;
> $have_rmks =
> !$CorrespondObj->Attachments->First->GetHeader('Received');
> }
> ### Lots of other code removed
> my $AddressGroup = "From: $FromAddress";
> $AddressGroup .= "\nCc: $Cc" if $Cc;
> $AddressGroup .= "\nBcc: $Bcc" if $Bcc;
> $OUT = "$AddressGroup
> Subject: Action completed
>
> The ticket that was opened for your request for host \"$mName\" has
> been
> resolved by $OwnerName. If you have any questions about this, you can
> contact us at $ContactAddress.
> $remarks
>
> Regards,
> Your Friendly IT Staff";
> }
> ===== END TEMPLATE CODE
>
> Another way to do this that actually uses a user-defined action with a
> template is to make the calls to the appropriate RT routines from
> within
> your scrip code. I did this with one of my scrips.
>
> I wanted to do some non-standard things with the recipients, so I
> modified RT's SetRecipients() routine and stuck it into my scrip, then
> I
> call it and make calls to the Prepare() and Commit() routines to build
> and send an e-mail using the designated template.
>
> ===== BEGIN SCRIP CODE
> ### Valid e-mail for ticket, send acknowledgment
> $self->SetRecipients();
> $self->SUPER::Prepare();
> $self->SUPER::Commit();
>
> sub SetRecipients {
> ### custom routine to do non-standard things with the recipients
> }
> 1;
> ===== END SCRIP CODE
>
> The above code snippet is at the end of my scrip's "Custom action
> preparation code" block.
>
> Regards,
> Gene
More information about the rt-users
mailing list