Scrip/template "Notify parent ticket owner on resolve"?

Does anyone know of a way to notify the parent ticket’s owner
on resolve?

Jeff,

Here’s some code I developed for a 3.8 installation.

It will add “TimeWorked” to each parent of a ticket up the ladder and
sideways (if a ticket has more than one parent), regardless of how many.

Use it as an example of how to determine if there is a parent and then as a
condition to send a notification.

Hope this helps.

Kenn

Custom condition:

Set initial values

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

Get out if not for “TimeWorked”

return 0 unless ($trans->Type eq ‘Set’ &&
$trans->Field eq ‘TimeWorked’);

return 1;

Custom action preparation code:

Set initial values

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $Time = (($trans->NewValue) - ($trans->OldValue));
my $MemberOf = $ticket->MemberOf;

get out if current ticket is not a “MemeberOf” (child of some parent)

return 0 unless $MemberOf;

Loop thru each parent and add the Child’s “TimeWorked” to them

You can skip a parent ticket if it is not in active state by uncommenting

the “next” statement

while( my $l = $MemberOf->Next )
{

next unless( $l->TargetObj->Status =~ /^(?:new|open|stalled)$/ );

 my $ParentTime = $l->TargetObj->TimeWorked;
 my $NewTime = ($ParentTime + $Time);
 $l->TargetObj->SetTimeWorked($NewTime);
}

return 1;

Custom action cleanup code: None

return 1;On Mon, Jun 4, 2012 at 10:04 AM, Jeff Blaine jblaine@kickflop.net wrote:

Does anyone know of a way to notify the parent ticket’s owner
on resolve?

That’s a good start to work with.

Any leads on the proper way to go about sending mail via a template
from inside a scrip would be welcome.

Do I just subclass Action::SendEmail, build my message, and commit()
it? I don’t see a way to reference/use a template for that.

 Condition: On Resolve

 Action: User-defined

 Template: ??????

 Custom condition code:

     N/A

 Custom action preparation code:

     if ticket has no parents
         return 1
     # otherwise... do stuff, send email

 Custom action cleanup code:

     return 1;

That’s a good start to work with.

Any leads on the proper way to go about sending mail via a template
from inside a scrip would be welcome.

This is what scrips are meant to do at their core. :wink:

Do I just subclass Action::SendEmail, build my message, and commit()
it? I don’t see a way to reference/use a template for that.

Condition: On Resolve

Action: User-defined

Template: ??????

Think about it this way. Make your Condition custom “On Resolve + Has
Parents”

Then use a standard Notify* action and set the Template on the scrip.

Thanks Thomas

Think about it this way. Make your Condition custom “On Resolve + Has
Parents”

Right.

Then use a standard Notify* action and set the Template on the scrip.

The goal is: On resolve of a child ticket, notify each parent
tickets’ owner
that the child was resolved.

There is no “standard Notify* action” for “Owners of parent
tickets”, so I’m confused by what you mean there.

You also said “the Template”. Are you suggesting that I write
the logic into a new custom template and force the “To:”
field there? Or did you intend “the Template” to mean any
existing template of my choice.

I really don’t follow you due to terseness, though I am certainly
not looking for anyone to provide the code either.

Jeff,

OK. Here’s what you do:

Create a Template called “Notify Parents on Resolve”.

The Template should have code similar to this (loop thru all parents and
add the Emailaddress of the ticket owner to the “To:” line in the Template)
at the top (test the code to correct my mistakes):To: {my $parent = $Ticket->MemberOf;);
my $OUTPUT;
while ( my $value = $parent->Next )
{
$OUTPUT .= $value->OwnerObj->EmailAddress;
$OUTPUT .= “<—\n”;
}
$OUTPUT;
}
Subject: This Child Ticket has been Resolved

Then create a scrip titled “Notify Parents of Resolved Child”.

The code should be like this:

Condition: User Defined

Action: Notify Others (“To:” address built by template code in

template below)

Template: Global template: Notify Parents of Resolved Child

Stage: TransactionBatch

Custom condition:

Set initial values

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

Check for value change on Ticket Status

return ($self->TransactionObj->Type eq “Status” &&
$self->TransactionObj->NewValue eq “resolved” &&
$MemberOf);

Custom action preparation code: None

Custom action clean-up code: None

Anyway, I just whipped this up and you should verify all the code. The
thing is you want to set a condition that tests that the ticket is being
resolved and it is a child. The template should have code that replaces the
"To:" address with the email address of the owner for any parent above and
that way all parents, grandparents, etc get an email saying that a child
ticket has been resolved. My code may be off but the mechanics should be
correct.

Hope this helps.

Kenn

Create a Template called “Notify Parents on Resolve”.

The Template should have code similar to this (loop thru all parents and
add the Emailaddress of the ticket owner to the “To:” line in the
Template) at the top (test the code to correct my mistakes):

To: {my $parent = $Ticket->MemberOf;); …

[snip]

Kenn,

That’s what I was stumbling toward, but it seemed like I was
perhaps missing a better way to do it. It can be a little
daunting trying to figure out where to customize RT before
you even get to the how part.

You could have just said, “Yes, override the To: with code
in a custom template”, but I’ll gladly take your much more
detailed response! :slight_smile:

Thanks.

PS: You got a tip via an Amazon purchase yesterday :wink:

Jeff,

Kool. Don’t forget about the action being “Notify Others” so your override
takes effect.

thanks for the tip on my guide.

KennOn Wed, Jun 6, 2012 at 9:31 AM, Jeff Blaine jblaine@kickflop.net wrote:

On 6/5/2012 6:40 PM, Kenneth Crocker wrote:

Create a Template called “Notify Parents on Resolve”.

The Template should have code similar to this (loop thru all parents and
add the Emailaddress of the ticket owner to the “To:” line in the
Template) at the top (test the code to correct my mistakes):

To: {my $parent = $Ticket->MemberOf;); …

[snip]

Kenn,

That’s what I was stumbling toward, but it seemed like I was
perhaps missing a better way to do it. It can be a little
daunting trying to figure out where to customize RT before
you even get to the how part.

You could have just said, “Yes, override the To: with code
in a custom template”, but I’ll gladly take your much more
detailed response! :slight_smile:

Thanks.

PS: You got a tip via an Amazon purchase yesterday :wink:

There are two solutions on the wiki that either open parent or put a
comment on it. One solution triggers when any dependency is resolved,
another when all child tickets are resolved. It is there for ages.

Ruslan from phone.04.06.2012 21:05 пользователь “Jeff Blaine” jblaine@kickflop.net написал:

Does anyone know of a way to notify the parent ticket’s owner
on resolve?