AutoSetOwner
Contributed by NicolasC
Overview
This custom action sets owner of the ticket to the current user if nobody yet owns the ticket. You can use this scrip action with any condition you want, for eg On Resolve
.
1 Description: AutoSetOwner
2 Condition: On Resolve
3 Action: User Defined
4 Custom action preparation code:
5 return 1;
6 Custom action cleanup code:
7 # get actor ID
8 my $Actor = $self->TransactionObj->Creator;
9 # if actor is RT_SystemUser then get out of here
10 return 1 if $Actor == $RT::SystemUser->id;
11 # prevents a ticket being assigned to an unprivileged user, comment out if you want this
12 return 1 unless $self->TransactionObj->CreatorObj->Privileged;
13 # get out unless ticket owner is nobody
14 return 1 unless $self->TicketObj->Owner == $RT::Nobody->id;
15 # ok, try to change owner
16 $RT::Logger->info("Auto assign ticket #". $self->TicketObj->id ." to user #". $Actor );
17 my ($status, $msg) = $self->TicketObj->SetOwner( $Actor );
18 unless( $status ) {
19 $RT::Logger->error( "Impossible to assign the ticket to $Actor: $msg" );
20 return undef;
21 }
22 return 1;
23 Template: Global template: Blank
N.B. If you do not have NotifyActor set and have the global default "On Owner Change Notify Owner with template Owner change" scrip, the above will notify the actor of the ticket being assigned to them as the SetOwner function creates a new transaction. To avoid this, use the following to set the ticket ownership:
$self->TicketObj->_Set(Field => 'Owner', Value => $Actor, RecordTransaction => 0);
This, as detailed on the WriteCustomAction page will not record the change as a transaction, thus preventing notification.
Changelog:
20050525/Rejo Added "Condition" line
20060105/HaimDimer Translated the remaning French into English.
Changed the severity of the error message from "warning" to "error"
20181105/Cris70 Fixed formatting of comments in code
20191001/Cris70 Added syntax highlighting
A variation on this theme is AutoSetOwnerIfAdminCc
Another variation is AutoSetOwnerForQueue