[rt-users] Templates and custom ScripActions

Francis L Fabrizio fabrizio at uab.edu
Sat Oct 23 12:20:33 EDT 2010


Thanks Gene, your code sample worked perfectly.  It is much easier to use one of the built-in Notify actions and place the logic in the template, rather than try to write a scrip with all the logic to send notifications.  Thanks for the guidance!

-Fran

> -----Original Message-----
> From: Gene LeDuc [mailto:gleduc at mail.sdsu.edu]
> Sent: Friday, October 22, 2010 1:42 PM
> To: Francis L Fabrizio
> Cc: rt-users at lists.bestpractical.com
> Subject: Re: [rt-users] Templates and custom ScripActions
> 
> Fran, I just did a quick test with a simple template and a custom
> field.
>   If my understanding of what you want to do is correct, the stuff
> below
> should work for you.
> 
> On 10/22/2010 10:06 AM, Francis L Fabrizio wrote:
> > 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?
> 
> Here is my scrip
> Condition: User Defined
> Action: Notify Requestors
> Template: Tell Gene
> Stage: TransactionCreate
> Custom condition:
> ===== BEGIN SCRIP CODE
> ### Trigger if custom value changed
> return $self->TransactionObj->Type =~ /CustomField/i;
> ===== END SCRIP CODE
> 
> Here is my "Tell Gene" template
> ===== BEGIN TEMPLATE CODE
> { ### Testing custom field changes from within a template
>    ### Get old and new values from the Transaction
>    my $old = $Transaction->OldValue();
>    my $new = $Transaction->NewValue();
>    my $field = $Transaction->Field();
> 
>    ### Get current value from the Ticket
>    my $curval = get_custom("Comments");
> 
>    ### Build the e-mail
>    $OUT = "From: me <me\@domain>
> To: me\@domain
> Subject: $New CF value
> 
> Using Transaction values
> ------------------------
> Field: '$field'
> Old value: '$old'
> New value: '$new'
> ------------------------
> 
> Using Ticket values
> ------------------------
> Current value: '$curval'
> ------------------------
> ";
> 
>    ### Returns custom field value
>    ### get_custom($field_name)
>    sub get_custom {
>      my $target_name = $_[0];
>      my $val = $Ticket->FirstCustomFieldValue($target_name);
>      return $val if defined $val;
>      return undef;
>    }
> }
> ===== END TEMPLATE CODE
> 
> 
> Here is the email I got when I changed the value of my "Comments" CF
> ===== BEGIN EMAIL
> From: me <me at domain>
> To: me at domain
> Subject: [myRT #4363] CF value
> 
> Using Transaction values
> ------------------------
> Field: '12'
> Old value: '54321'
> New value: '123'
> ------------------------
> 
> Using Ticket values
> ------------------------
> Current value: '123'
> ------------------------
> ===== END EMAIL



More information about the rt-users mailing list