<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: Times New Roman; font-size: 12pt; color: #000000'>This code was entered in a template not a script. I was trying Kevin's suggestion with doing it all in one go. I figure that if I can capture the CustomField in the template code and test on that value to return my $to_address, then I am pretty much set to create my outgoing e-mail at the same time. <span><br><br><br><br><span name="x"></span>Kurt Engle<br>Network Engineer<br>Eugene 4J Schools<span name="x"></span><br></span><br><hr id="zwchr"><b>From: </b>"Kenneth Crocker" <kfcrocker@lbl.gov><br><b>To: </b>rt-users@lists.bestpractical.com<br><b>Sent: </b>Monday, December 13, 2010 12:12:50 PM<br><b>Subject: </b>Re: [rt-users] notification<br><br>Kurt,<br><br> Not sure why you start the scrip with a "{" and end with one. Just start with the "my $trans=".<br><br>Your code should be in the "Prep Action" and you should add this at the end of the code you've got:<br>
<br>else {<br> $to_address= "rubble";<br><br>### after the above line, the code should look like this: ####<br><br># copy value of "To_Address" to Custom Field "Whatever you named it"<br>
<br>my $cf_name = "Whatever it is";<br><br>$cf_obj->LoadByName( Name => $cf_name );<br>$RT::Logger->debug( "Loaded \$cf_obj->Name = ". $cf_obj->Name() ."\n" );<br>$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$to_address, RecordTransaction=>0);<br>
<br>return 1;<br><br>Then make sure the "Cleanup Action" ends with a "return 1;" or the scrip doesn't finish.<br>Also, not sure why you start the scrip with a "{" and end with one. Just start with the "my $trans=".<br>
<br><br>The Template should refer to the value in the CF you created for the "To Address", like this:<br><br>To: {$Ticket->FirstCustomFieldValue('To Address Value')}@<a href="http://4j.lane.edu" target="_blank">4j.lane.edu</a><br>
Subject: Request Titled: "{$Ticket->Subject}" is ready to Migrate or whatever<br><br>That should do it.<br><br>Kenn<br>LBNL<br><div class="gmail_quote">On Mon, Dec 13, 2010 at 11:15 AM, Kurt Engle <span dir="ltr"><<a href="mailto:engle@4j.lane.edu" target="_blank">engle@4j.lane.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div style="font-family: Times New Roman; font-size: 12pt; color: rgb(0, 0, 0);">So here is the code that I am working with inside my template:<br>
Script:<br>Condition: On Create<br>Action: Notify Other Recipients<br>Template: My Notify<br>Stage: TransactionBatch<br><br>'My Notify' code<br>-------------------------------------------<br>{<br>my $trans = $self->TransactionObj;<br>
my $ticket = $self->TicketObj;<br>my $cf = new RT::CustomField($RT::SystemUser);<br>$cf->LoadByName(Queue => $ticket->QueueObj->id,Name => "Building");<br>return 0 unless $cf->id;<br>my $cfvalue = $ticket->FirstCustomFieldValue('Building');<br>
<br>my $to_address = "";<br><br>if ($cfvalue =~ /Sheldon/) {<br> $to_address = "sheldonhd";<br>}<br>elsif ($cfvalue =~ /North/) {<br> $to_address = "northhd";<br>}<br>elsif ($cfvalue =~ /South/) {<br>
$to_address = "southhd";<br>}<br>elsif ($cfvalue =~ /Churchill/) {<br> $to_address = "churchillhd";<br>}<br>elsif ($cfvalue =~ /Kennedy/) {<br> $to_address = "kennedyhd";<br>}<br>
elsif ($cfvalue =~ /Kelly/) {<br> $to_address = "kellyhd";<br>}<br>elsif ($cfvalue =~ /Computer/) {<br> $to_address = "engle";<br>else {<br> $to_address= "rubble";<br>}<br>return 1;<br>
}<br><br><br>To: {$<a href="mailto:to_address%7D@4j.lane.edu" target="_blank">to_address}@4j.lane.edu</a>"}<br>Subject: New Ticket #{ $Ticket->Id() } has been created<br><br>Time to go to work<br>----------------------------------<br>
<br>In my debug log, I am not even seeing the script being called that contains this template. If I strip everything above the 'To:' field, the scrip and template gets called but the e-mail is not sent even when I hard code the e-mail address.<br>
<br><br><span><br><span></span>Kurt Engle<br></span><br><hr><b>From: </b>"Kevin Falcone" <<a href="mailto:falcone@bestpractical.com" target="_blank">falcone@bestpractical.com</a>><br><b>To: </b><a href="mailto:rt-users@lists.bestpractical.com" target="_blank">rt-users@lists.bestpractical.com</a><br>
<b>Sent: </b>Friday, December 10, 2010 12:23:28 PM<br><b>Subject: </b>Re: [rt-users] notification<br><br>On Fri, Dec 10, 2010 at 12:08:05PM -0800, Kenneth Crocker wrote:<br>> Kevin,<br>> The template would look like this:<br>
<br>Kenn<br><br>I'm perfectly able to write the scrip and template in question, but<br>since Kurt has a half-working template I was curious what *he* was<br>doing. Involving a CustomField seems like a bit of overkill.<br>
<br>-kevin<br><br>> To: {$Ticket->FirstCustomFieldValue('ToOverride')}@[1]<a href="http://lbl.gov" target="_blank">lbl.gov</a><br>> Subject: Request Titled: "{$Ticket->Subject}" is ready to Migrate!<br>
> <br>> A scrip based on whatever condition would do this:<br>> <br>> my $trans = $self->TransactionObj;<br>> my $ticket = $self->TicketObj;<br>> my $cf_obj = new RT::CustomField($RT::SystemUser);<br>
> my $cf_name = "ToOverride";<br>> <br>> if condition is "A"<br>> $my $cf_value = "the To address you want for "A" condition";<br>> elsif condition is "B"<br>
> $my $cf_value = "the To address you want for "B" condition";<br>> <br>> and on and on till you're thru.<br>> <br>> then, set the Custom Field as the last piece of action code:<br>
> <br>> $cf_obj->LoadByName(Name=>$cf_name);<br>> $RT::Logger->debug("Loaded\$cf_obj->Name = ". $cf_obj->Name() ."\n" );<br>> $ticket->AddCustomFieldValue( Field=>$cf_obj, Value=>$cf_value, RecordTransaction=>0 );<br>
> <br>> return 1;<br>> <br>> Then write a notification scrip to use the new template based on your conditions.<br>> Use "TransactioBatch" for both scrips.<br>> <br>> Hope this helps.<br>
> <br>> Kenn<br>> LBNL<br>> <br>> On Fri, Dec 10, 2010 at 11:55 AM, Kevin Falcone <[2]<a href="mailto:falcone@bestpractical.com" target="_blank">falcone@bestpractical.com</a>> wrote:<br>> <br>
> On Fri, Dec 10, 2010 at 11:07:32AM -0800, Kurt Engle wrote:<br>> > Actually found a nice example of creating a template to send out an e-mail. RTFM....<br>> ><br>> > However, I am having a bit of a problem constructing the To: field. Basically, I have a<br>
> > varialble '$toAddress' that is set to an e-mail address by some prior code.<br>> <br>> Where in the code is it set. It would really need to be in that<br>> template<br>> > Here is my template code to construct the To: field:<br>
> > To: { $toAddress }<br>> > Subject: Ticket #{ $Ticket->Id()} {$Ticket->Subject()}<br>> > A new ticket has been created for you in the HelpDesk Queue.<br>> ><br>> > { $RT::WebURL } Ticket/Display.html?id={ $Ticket->Id() }<br>
> ><br>> > However, I keep getting 'recipient not found'.<br>> <br>> In debug logging mode, RT will actually dump copies of the email being<br>> processed into the logs, which would show you the To:<br>
> <br>> Please note that if To: is your email address and you're the actor on<br>> this ticket while testing, you may have told RT not to send you email<br>> in that case using $NotifyActor<br>
> -kevin<br>> <br>> ><br>> ----------------------------------------------------------------------------------------------<br>> ><br>> > From: "Kevin Falcone" <[3]<a href="mailto:falcone@bestpractical.com" target="_blank">falcone@bestpractical.com</a>><br>
> > To: [4]<a href="mailto:rt-users@lists.bestpractical.com" target="_blank">rt-users@lists.bestpractical.com</a><br>> > Sent: Friday, December 10, 2010 10:03:04 AM<br>> > Subject: Re: [rt-users] notification<br>
> ><br>> > On Fri, Dec 10, 2010 at 09:55:07AM -0800, Kurt Engle wrote:<br>> > > That is correct. But how do I make use of the RT::Action::SendEmail module to send the<br>> > > notification incorporating my To: field. Or is there a better way to send out a custom<br>
> > > notification?<br>> ><br>> > You use one of the standard Notify actions and a custom template. You<br>> > don't write any code in the action and you don't call the action<br>
> > directly.<br>> ><br>> > -kevin<br>> ><br>> > > From: "Kevin Falcone" <[5]<a href="mailto:falcone@bestpractical.com" target="_blank">falcone@bestpractical.com</a>><br>
> > > To: [6]<a href="mailto:rt-users@lists.bestpractical.com" target="_blank">rt-users@lists.bestpractical.com</a><br>> > > Sent: Friday, December 10, 2010 8:59:25 AM<br>> > > Subject: Re: [rt-users] notification<br>
> > ><br>> > > On Thu, Dec 09, 2010 at 11:42:03AM -0800, Kurt Engle wrote:<br>> > > > I am looking for a way to send an email from RT to a specified e-mail address that<br>> > is not<br>
> > > an<br>> > > > account in RT or associated with the ticket as a requestor, watcher, CC:,<br>> > BCC:...etc....<br>> > > ><br>> > > > I have the logic down to specify the e-mail address and have some nasty perl code to<br>
> > > actually<br>> > > > send the e-mail. But, it seems that RT has some internal module(s) that handle what<br>> > the<br>> > > nasty<br>> > > > perl code is doing.<br>
> > > ><br>> > > > I can see the RT::Action:SendEmail module, but how do I incorporate that into a<br>> > script<br>> > > that<br>> > > > allows me to do what I am looking to do?<br>
> > ><br>> > > Sounds like you actually just want to use a normal Notify action, but<br>> > > have the template contain your ugly logic that sets up the To: line<br>> > > based on your perl code<br>
> > ><br>> > > -kevin<br>> <br>> References<br>> <br>> Visible links<br>> 1. <a href="http://lbl.gov/" target="_blank">http://lbl.gov/</a><br>> 2. mailto:<a href="mailto:falcone@bestpractical.com" target="_blank">falcone@bestpractical.com</a><br>
> 3. mailto:<a href="mailto:falcone@bestpractical.com" target="_blank">falcone@bestpractical.com</a><br>> 4. mailto:<a href="mailto:rt-users@lists.bestpractical.com" target="_blank">rt-users@lists.bestpractical.com</a><br>
> 5. mailto:<a href="mailto:falcone@bestpractical.com" target="_blank">falcone@bestpractical.com</a><br>> 6. mailto:<a href="mailto:rt-users@lists.bestpractical.com" target="_blank">rt-users@lists.bestpractical.com</a><br>
</div></div></blockquote></div><br>
</div></body></html>