Send email from template

Hi,

I’m trying to send an email from template, initiated by rt-crontool as
described in wiki, the only trick is that dependent on custom field it
should be sent to other persons group. Here my template, somehow it always
send to user1 and user 2.

RT-Send-Cc: { my $values = $Ticket->CustomFieldValues(‘CIT_Category’);
my $OUTPUT;
my $CFValue;
while ( my $value = $values->Next ) {
$CFValue = $value->Content;
if ($CFValue == ‘IT Facilites’) { $OUTPUT = ‘user1@dom.com,
user2@dom.com’ }
elsif ($CFValue == ‘Linux/Network’) { $OUTPUT = ‘user3@dom.com,
user4@dom.com’ }
elsif ($CFValue == ‘Phone’) { $OUTPUT = ‘user5@dom.com, user6@dom.com
}
elsif ($CFValue == ‘Windows’) { $OUTPUT = ‘user7@dom.com, user8@dom.com
}
}
$OUTPUT;
}

The ticket {$Ticket->id} stayed unowned for 30 minutes.

Please do a categorisation, assign optionally an owner!

Any idea what I’m doing wrong, maybe there is some, more elegant method to
do a custom field based escalation, here is how I’am starting the
rt-crontool:

rt-crontool --search RT::Search::FromSQL --search-arg “id = 23331” --action
RT::Action::RecordComment --template ‘UnownedNotifyWatcherLevel1’

Thanks in advance,

Ivan Samarin

Thank you Jeff, works perfect, I forgot that “==” is used only for numbers,
not strings…

Ivan2010/5/3 Jeff Voskamp javoskam@uwaterloo.ca

On 05/03/2010 11:49 AM, Givano wrote:

Hi,

I’m trying to send an email from template, initiated by rt-crontool as
described in wiki, the only trick is that dependent on custom field it
should be sent to other persons group. Here my template, somehow it always
send to user1 and user 2.

########################
Subject: new ticket, 30 minutes unowned!
RT-Send-Cc: { my $values = $Ticket->CustomFieldValues(‘CIT_Category’);
my $OUTPUT;
my $CFValue;
while ( my $value = $values->Next ) {
$CFValue = $value->Content;
if ($CFValue == ‘IT Facilites’) { $OUTPUT = ‘user1@dom.com <mailto:
user1@dom.com>, user2@dom.com mailto:user2@dom.com’ }
elsif ($CFValue == ‘Linux/Network’) { $OUTPUT = ‘user3@dom.com<mailto:
user3@dom.com>, user4@dom.com mailto:user4@dom.com’ }
elsif ($CFValue == ‘Phone’) { $OUTPUT = ‘user5@dom.com <mailto:
user5@dom.com>, user6@dom.com mailto:user6@dom.com’ }
elsif ($CFValue == ‘Windows’) { $OUTPUT = ‘user7@dom.com <mailto:
user7@dom.com>, user8@dom.com mailto:user8@dom.com’ }

}
$OUTPUT;
}

The ticket {$Ticket->id} stayed unowned for 30 minutes.

Please do a categorisation, assign optionally an owner!
######################################

Try using ‘eq’ instead of ‘==’ - you want to compare the values of the
string, not if it’s set.
You might also want to use ‘.=’ instead of ‘=’ for $OUTPUT if you are
handling multiple values for CIT_Category, but watch out for missing commas.

Jeff

Givano,

I have a scrip that sets the owner based on the value in a Custom Field.
Look at it and modify it to meet your needs:

Custom Action preparation code

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;

set new ticket owner id value

42 - Bob

148 - Carol

5125 - Ted

9324 - Alice

my %orgs = qw(
Budget 148
Controller 5125
Facilities 42
Field-OPS 5125
Property 9324
SPO 148
Travel 5125
Other 42
);

my $cf = new RT::CustomField($RT::SystemUser);
$cf->LoadByName(Queue => $ticket->QueueObj->id,Name => “CFO-Org”);

check for valid CF-Org value first,

then set new Ticket Owner ID

if ($cf->id)
{
my $cfvalue = $ticket->FirstCustomFieldValue(‘CFO-Org’);
my $ownerid = $orgs{$cfvalue};
$ticket->SetOwner($ownerid);
}

return 1;

You could easily replace the owner Ids with your email address and instead
of setting the ownerid, set the “To” address or whatever.

Anyway, hope this helps. It sure works for us.

Kenn
LBNLOn Mon, May 3, 2010 at 8:49 AM, Givano givano@gmail.com wrote:

Hi,

I’m trying to send an email from template, initiated by rt-crontool as
described in wiki, the only trick is that dependent on custom field it
should be sent to other persons group. Here my template, somehow it always
send to user1 and user 2.

########################
Subject: new ticket, 30 minutes unowned!
RT-Send-Cc: { my $values = $Ticket->CustomFieldValues(‘CIT_Category’);
my $OUTPUT;
my $CFValue;
while ( my $value = $values->Next ) {
$CFValue = $value->Content;
if ($CFValue == ‘IT Facilites’) { $OUTPUT = ‘user1@dom.com,
user2@dom.com’ }
elsif ($CFValue == ‘Linux/Network’) { $OUTPUT = ‘user3@dom.com,
user4@dom.com’ }
elsif ($CFValue == ‘Phone’) { $OUTPUT = ‘user5@dom.com, user6@dom.com
}
elsif ($CFValue == ‘Windows’) { $OUTPUT = ‘user7@dom.com,
user8@dom.com’ }
}
$OUTPUT;
}

The ticket {$Ticket->id} stayed unowned for 30 minutes.

Please do a categorisation, assign optionally an owner!
######################################

Any idea what I’m doing wrong, maybe there is some, more elegant method to
do a custom field based escalation, here is how I’am starting the
rt-crontool:

rt-crontool --search RT::Search::FromSQL --search-arg “id = 23331” --action
RT::Action::RecordComment --template ‘UnownedNotifyWatcherLevel1’

Thanks in advance,

Ivan Samarin

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Hello Kenn,

thanks for your scrip, I’m using the rt-crontool for ticket escalation and
could not find out how to use custom actions with rt-crontool, maybe you
have a hint for me.

Thanks, Ivan2010/5/3 Kenneth Crocker kfcrocker@lbl.gov

Givano,

I have a scrip that sets the owner based on the value in a Custom Field.
Look at it and modify it to meet your needs:

Custom Action preparation code

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;

set new ticket owner id value

42 - Bob

148 - Carol

5125 - Ted

9324 - Alice

my %orgs = qw(
Budget 148
Controller 5125
Facilities 42
Field-OPS 5125
Property 9324
SPO 148
Travel 5125
Other 42
);

my $cf = new RT::CustomField($RT::SystemUser);
$cf->LoadByName(Queue => $ticket->QueueObj->id,Name => “CFO-Org”);

check for valid CF-Org value first,

then set new Ticket Owner ID

if ($cf->id)
{
my $cfvalue = $ticket->FirstCustomFieldValue(‘CFO-Org’);
my $ownerid = $orgs{$cfvalue};
$ticket->SetOwner($ownerid);
}

return 1;

You could easily replace the owner Ids with your email address and instead
of setting the ownerid, set the “To” address or whatever.

Anyway, hope this helps. It sure works for us.

Kenn
LBNL

On Mon, May 3, 2010 at 8:49 AM, Givano givano@gmail.com wrote:

Hi,

I’m trying to send an email from template, initiated by rt-crontool as
described in wiki, the only trick is that dependent on custom field it
should be sent to other persons group. Here my template, somehow it always
send to user1 and user 2.

########################
Subject: new ticket, 30 minutes unowned!
RT-Send-Cc: { my $values = $Ticket->CustomFieldValues(‘CIT_Category’);
my $OUTPUT;
my $CFValue;
while ( my $value = $values->Next ) {
$CFValue = $value->Content;
if ($CFValue == ‘IT Facilites’) { $OUTPUT = ‘user1@dom.com,
user2@dom.com’ }
elsif ($CFValue == ‘Linux/Network’) { $OUTPUT = ‘user3@dom.com,
user4@dom.com’ }
elsif ($CFValue == ‘Phone’) { $OUTPUT = ‘user5@dom.com,
user6@dom.com’ }
elsif ($CFValue == ‘Windows’) { $OUTPUT = ‘user7@dom.com,
user8@dom.com’ }
}
$OUTPUT;
}

The ticket {$Ticket->id} stayed unowned for 30 minutes.

Please do a categorisation, assign optionally an owner!
######################################

Any idea what I’m doing wrong, maybe there is some, more elegant method to
do a custom field based escalation, here is how I’am starting the
rt-crontool:

rt-crontool --search RT::Search::FromSQL --search-arg “id = 23331”
–action RT::Action::RecordComment --template ‘UnownedNotifyWatcherLevel1’

Thanks in advance,

Ivan Samarin

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com