Automatic assignment of tickets

Hi all,

I’m trying to automatically assign tickets whenever someone either

a) comments a ticket or alternatively,
b) responds to a ticket

The conditions are that the current owner is Nobody and the user cannot be
user ‘X’ (my supervisor for instance, might post comments on a ticket first,
but he’s the boss and we want to exclude him from getting ownership.)
Here’s the Scrip I put together thus far. If anyone can shed some light,
that’d be great!

PS: If there is a better forum for me to post this on, I’d be more than
happy to not waste any of your bandwidth and go there.

Description: Ticket Auto Assign
Condition: On Comment (I’m not sure how to get On Comment AND On reply at
the same time? Need two different Scrips?)
Action: User Defined
Template: Global Template: Transaction (I’m not sure what this does, need to
look it up on the Wiki)
Stage: Disabled (No idea what this one does either …)
Custom Condition:
Custom Action Preparation Code:

my $notOwner = “billybob”; # I don’t want billybob to get assigned any
tickets no matter if he replies first
my $Actor = $self->TransactionObj->Creator;

return 1 unless $self->TicketObj->Owner == $RT::Nobody->id;
$RT::Logger->info(“Auto assign ticket #”. $self->TicketObj->id ." to user
#". $Actor );
my ($status, $msg) = $self->TicketObj->SetOwner( $Actor ) unless $Actor ==
$notOwner;
unless ( $status ) {
$RT::Logger->error( “Impossible to assign the ticket to $Actor: $msg” );
return undef;
}
return 1;
Custom action cleanup code: return 1;

This doesn’t look to do the trick. Any suggestions again, would be more than
appreciated.

Thanks all!
Steve

Hi all,

I'm trying to automatically assign tickets whenever someone either 

a) comments a ticket or alternatively,
b) responds to a ticket

The conditions are that the current owner is Nobody and the user

cannot be user ‘X’ (my supervisor for instance, might post comments on a
ticket first, but he’s the boss and we want to exclude him from getting
ownership.) Here’s the Scrip I put together thus far. If anyone can shed
some light, that’d be great!

PS: If there is a better forum for me to post this on, I'd be more

than happy to not waste any of your bandwidth and go there.

Description: Ticket Auto Assign
Condition: On Comment (I'm not sure how to get On Comment AND On

reply at the same time? Need two different Scrips?)
Action: User Defined
Template: Global Template: Transaction (I’m not sure what this does,
need to look it up on the Wiki)
Stage: Disabled (No idea what this one does either …)
Custom Condition:
Custom Action Preparation Code:

my $notOwner = "billybob"; # I don't want billybob to get assigned

any tickets no matter if he replies first
my $Actor = $self->TransactionObj->Creator;

return 1 unless $self->TicketObj->Owner == $RT::Nobody->id; 
$RT::Logger->info("Auto assign ticket #". $self->TicketObj->id ." to

user #". $Actor );
my ($status, $msg) = $self->TicketObj->SetOwner( $Actor ) unless
$Actor == $notOwner;
unless ( $status ) {
$RT::Logger->error( “Impossible to assign the ticket to $Actor:
$msg” );
return undef;
}
return 1;
Custom action cleanup code: return 1;

This doesn't look to do the trick. Any suggestions again, would be

more than appreciated.

Thanks all!
Steve 

Hi Steve,

This is exactly the right forum!

You don’t mention what’s actually happening - in what way is this failing?
Are there error messages in the RT log when this scrip is activated? Or does
it just silently not do what you want?

To have the scrip respond to either a comment or a reply, you could use a
custom/user-defined condition that checks the transaction type - relevant
values are ‘Comment’ and ‘Correspond’.

For scrips that don’t need to send email, you should use the Blank template.

I did notice one thing in the code: “unless $Actor == $notOwner”. This won’t
work, as $Actor is an Id number whereas $notOwner is a user name (string).
You can get the user name of the “actor” by doing
$self->TransactionObj->CreatorObj->Name.

Good luck,
Steve

Stephen Turner
Senior Programmer/Analyst - Client Support Services
MIT Information Services and Technology (IS&T)

Apologies, I sent my original reply to Drew personally instead of the list.
Here’s one other question I had:

Drew,

That helped a ton, shesh. Not sure how I missed it!

Another question. Is there a condition which meets BOTH a comment AND a
reply? Would On Correspondance fit that category?

Thanks a ton, this is great.On 10/11/06, Steve Finkelstein stevefink@gmail.com wrote:

Drew,

That helped a ton, shesh. Not sure how I missed it!

Another question. Is there a condition which meets BOTH a comment AND a
reply? Would On Correspondance fit that category?

Thanks a ton, this is great.

– Steve

On 10/11/06, Drew Barnes barnesaw@ucrwcu.rwc.uc.edu wrote:

Stage: Disabled means the scrip won’t run. You need to set that to
TransactionCreate before it will even have a chance.

DB

Steve Finkelstein wrote:

Hi all,

I’m trying to automatically assign tickets whenever someone either

a) comments a ticket or alternatively,
b) responds to a ticket

The conditions are that the current owner is Nobody and the user
cannot be user ‘X’ (my supervisor for instance, might post comments on

a ticket first, but he’s the boss and we want to exclude him from
getting ownership.) Here’s the Scrip I put together thus far. If
anyone can shed some light, that’d be great!

PS: If there is a better forum for me to post this on, I’d be more
than happy to not waste any of your bandwidth and go there.

Description: Ticket Auto Assign
Condition: On Comment (I’m not sure how to get On Comment AND On reply
at the same time? Need two different Scrips?)
Action: User Defined
Template: Global Template: Transaction (I’m not sure what this does,
need to look it up on the Wiki)
Stage: Disabled (No idea what this one does either …)
Custom Condition:
Custom Action Preparation Code:

my $notOwner = “billybob”; # I don’t want billybob to get assigned any
tickets no matter if he replies first
my $Actor = $self->TransactionObj->Creator;

return 1 unless $self->TicketObj->Owner == $RT::Nobody->id;
$RT::Logger->info(“Auto assign ticket #”. $self->TicketObj->id ." to
user #". $Actor );
my ($status, $msg) = $self->TicketObj->SetOwner( $Actor ) unless
$Actor == $notOwner;
unless ( $status ) {
$RT::Logger->error( “Impossible to assign the ticket to $Actor:
$msg” );
return undef;
}
return 1;
Custom action cleanup code: return 1;

This doesn’t look to do the trick. Any suggestions again, would be
more than appreciated.

Thanks all!

Steve



The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

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


Drew Barnes
Applications Analyst
Raymond Walters College
University of Cincinnati

Stephen,

Thanks much for the reply. So I had this code working before, but the
following seems to have broken it:

my $notOwner1 = “foo”;
my $notOwner2 = “bar”;

my $Actor = $self->TransactionObj->CreatorObj->Name;

return 1 unless $self->TicketObj->Owner == $RT::Nobody->id;
$RT::Logger->info(“Auto assign ticket #”. $self->TicketObj->id ." to user
#". $Actor );
my ($status, $msg) = $self->TicketObj->SetOwner( $Actor ) unless ($Actor ==
$notOwner1 || $Actor == $notOwner2);
unless ( $status ) {
$RT::Logger->error( “Impossible to assign the ticket to $Actor: $msg” );
return undef;
}
return 1;

I make a comment as a non-foo user and it keeps owner as nobody. I’ve tried
a different assortment of booleans to see which this particular perl
interpreter will take without much luck. I’m also trying to find as much
documentation as I can on all the methods and objects that’re available for
use.

Thanks so much for your reply. If you have any insight on this particular
segment, I’d really appreciate it.

– SteveOn 10/11/06, Stephen Turner sturner@mit.edu wrote:

    Hi all,

    I'm trying to automatically assign tickets whenever someone either

    a) comments a ticket or alternatively,
    b) responds to a ticket

    The conditions are that the current owner is Nobody and the user

cannot be user ‘X’ (my supervisor for instance, might post comments on a
ticket first, but he’s the boss and we want to exclude him from getting
ownership.) Here’s the Scrip I put together thus far. If anyone can shed
some light, that’d be great!

    PS: If there is a better forum for me to post this on, I'd be more

than happy to not waste any of your bandwidth and go there.

    Description: Ticket Auto Assign
    Condition: On Comment (I'm not sure how to get On Comment AND On

reply at the same time? Need two different Scrips?)
Action: User Defined
Template: Global Template: Transaction (I’m not sure what this
does,
need to look it up on the Wiki)
Stage: Disabled (No idea what this one does either …)
Custom Condition:
Custom Action Preparation Code:

    my $notOwner = "billybob"; # I don't want billybob to get assigned

any tickets no matter if he replies first
my $Actor = $self->TransactionObj->Creator;

    return 1 unless $self->TicketObj->Owner == $RT::Nobody->id;
    $RT::Logger->info("Auto assign ticket #". $self->TicketObj->id ."

to
user #". $Actor );
my ($status, $msg) = $self->TicketObj->SetOwner( $Actor ) unless
$Actor == $notOwner;
unless ( $status ) {
$RT::Logger->error( “Impossible to assign the ticket to
$Actor:
$msg” );
return undef;
}
return 1;
Custom action cleanup code: return 1;

    This doesn't look to do the trick. Any suggestions again, would be

more than appreciated.

    Thanks all!
    --
    Steve

Hi Steve,

This is exactly the right forum!

You don’t mention what’s actually happening - in what way is this failing?
Are there error messages in the RT log when this scrip is activated? Or
does
it just silently not do what you want?

To have the scrip respond to either a comment or a reply, you could use a
custom/user-defined condition that checks the transaction type - relevant
values are ‘Comment’ and ‘Correspond’.

For scrips that don’t need to send email, you should use the Blank
template.

I did notice one thing in the code: “unless $Actor == $notOwner”. This
won’t
work, as $Actor is an Id number whereas $notOwner is a user name (string).
You can get the user name of the “actor” by doing
$self->TransactionObj->CreatorObj->Name.

Good luck,
Steve


Stephen Turner
Senior Programmer/Analyst - Client Support Services
MIT Information Services and Technology (IS&T)

Is it possible at all to debug the code somehow? It’s tough to debug as I’m
not able to get any output back from RT. If there is somewhere I can enable
logs for this, that’d be great. Here’s my latest revision with Stephen’s
suggestions. I’ll pin point the line which causes the code to fail. If I
remove it, it assigns the ticket to whoever last corresponds. However, I
need it to not assign based if two individual users make a correspondance.
Those users are “foo” and “bar”.

my $Actor = $self->TransactionObj->CreatorObj->Name;

return 1 if ( $Actor == “foo” || $Actor == “bar”); # This is the line that’s
causing the Scrip to fail. No one gets assigned a ticket.
return 1 unless $self->TicketObj->Owner == $RT::Nobody->id;
$RT::Logger->info(“Auto assign ticket #”. $self->TicketObj->id ." to user
#". $Actor );
my ($status, $msg) = $self->TicketObj->SetOwner( $Actor );
unless ( $status ) {
$RT::Logger->error( “Impossible to assign the ticket to $Actor: $msg” );
return undef;
}
return 1;

Thanks again everyone for your help.

– SteveOn 10/11/06, Stephen Turner sturner@mit.edu wrote:

    Hi all,

    I'm trying to automatically assign tickets whenever someone either

    a) comments a ticket or alternatively,
    b) responds to a ticket

    The conditions are that the current owner is Nobody and the user

cannot be user ‘X’ (my supervisor for instance, might post comments on a
ticket first, but he’s the boss and we want to exclude him from getting
ownership.) Here’s the Scrip I put together thus far. If anyone can shed
some light, that’d be great!

    PS: If there is a better forum for me to post this on, I'd be more

than happy to not waste any of your bandwidth and go there.

    Description: Ticket Auto Assign
    Condition: On Comment (I'm not sure how to get On Comment AND On

reply at the same time? Need two different Scrips?)
Action: User Defined
Template: Global Template: Transaction (I’m not sure what this
does,
need to look it up on the Wiki)
Stage: Disabled (No idea what this one does either …)
Custom Condition:
Custom Action Preparation Code:

    my $notOwner = "billybob"; # I don't want billybob to get assigned

any tickets no matter if he replies first
my $Actor = $self->TransactionObj->Creator;

    return 1 unless $self->TicketObj->Owner == $RT::Nobody->id;
    $RT::Logger->info("Auto assign ticket #". $self->TicketObj->id ."

to
user #". $Actor );
my ($status, $msg) = $self->TicketObj->SetOwner( $Actor ) unless
$Actor == $notOwner;
unless ( $status ) {
$RT::Logger->error( “Impossible to assign the ticket to
$Actor:
$msg” );
return undef;
}
return 1;
Custom action cleanup code: return 1;

    This doesn't look to do the trick. Any suggestions again, would be

more than appreciated.

    Thanks all!
    --
    Steve

Hi Steve,

This is exactly the right forum!

You don’t mention what’s actually happening - in what way is this failing?
Are there error messages in the RT log when this scrip is activated? Or
does
it just silently not do what you want?

To have the scrip respond to either a comment or a reply, you could use a
custom/user-defined condition that checks the transaction type - relevant
values are ‘Comment’ and ‘Correspond’.

For scrips that don’t need to send email, you should use the Blank
template.

I did notice one thing in the code: “unless $Actor == $notOwner”. This
won’t
work, as $Actor is an Id number whereas $notOwner is a user name (string).
You can get the user name of the “actor” by doing
$self->TransactionObj->CreatorObj->Name.

Good luck,
Steve


Stephen Turner
Senior Programmer/Analyst - Client Support Services
MIT Information Services and Technology (IS&T)

Is it possible at all to debug the code somehow? It’s tough to debug
as I’m not able to get any output back from RT. If there is somewhere
I can enable logs for this, that’d be great. Here’s my latest revision
with Stephen’s suggestions. I’ll pin point the line which causes the
code to fail. If I remove it, it assigns the ticket to whoever last
corresponds. However, I need it to not assign based if two individual
users make a correspondance. Those users are “foo” and “bar”.

my $Actor = $self->TransactionObj->CreatorObj->Name;

return 1 if ( $Actor == “foo” || $Actor == “bar”); # This is the line
that’s causing the Scrip to fail. No one gets assigned a ticket.

I think your problem is the numerical equivalence operators (==). You
are comparing strings so you should either use the string equivalent, eq
or a regex test with =~. The above expression will probably always
return true (depending on the value of $Actor) so the scrip never goes
beyond this line.