[rt-users] Templates and custom ScripActions

Gene LeDuc gleduc at mail.sdsu.edu
Fri Oct 22 14:42:18 EDT 2010


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