AutoSetOwner: Difference between revisions
Jump to navigation
Jump to search
m (4 revisions imported) |
m (Fixed formatting of comments in code) |
||
Line 11: | Line 11: | ||
return 1; | return 1; | ||
Custom action cleanup code: | Custom action cleanup code: | ||
# get actor ID | \# get actor ID | ||
my $Actor = $self->TransactionObj->Creator; | my $Actor = $self->TransactionObj->Creator;<br /> | ||
\# if actor is RT_SystemUser then get out of here | |||
# if actor is RT_SystemUser then get out of here | return 1 if $Actor == $RT::SystemUser->id;<br /> | ||
return 1 if $Actor == $RT::SystemUser->id; | \# prevents a ticket being assigned to an unprivileged user, comment out if you want this | ||
return 1 unless $self->TransactionObj->CreatorObj->Privileged;<br /> | |||
# prevents a ticket being assigned to an unprivileged user, comment out if you want this | \# get out unless ticket owner is nobody | ||
return 1 unless $self->TransactionObj->CreatorObj->Privileged; | return 1 unless $self->TicketObj->Owner == $RT::Nobody->id;<br /> | ||
\# ok, try to change owner | |||
# get out unless ticket owner is nobody | |||
return 1 unless $self->TicketObj->Owner == $RT::Nobody->id; | |||
# ok, try to change owner | |||
$RT::Logger->info("Auto assign ticket #". $self->TicketObj->id ." to user #". $Actor ); | $RT::Logger->info("Auto assign ticket #". $self->TicketObj->id ." to user #". $Actor ); | ||
my ($status, $msg) = $self->TicketObj->SetOwner( $Actor ); | my ($status, $msg) = $self->TicketObj->SetOwner( $Actor ); | ||
Line 45: | Line 41: | ||
20060105/HaimDimer Translated the remaning French into English. | 20060105/HaimDimer Translated the remaning French into English. | ||
Changed the severity of the error message from "warning" to "error" | Changed the severity of the error message from "warning" to "error" | ||
20181105/Cris70 Fixed formatting of comments in code | |||
A variation on this theme is [[AutoSetOwnerIfAdminCc]] | A variation on this theme is [[AutoSetOwnerIfAdminCc]] | ||
Another variation is [[AutoSetOwnerForQueue]] | Another variation is [[AutoSetOwnerForQueue]] |
Revision as of 03:41, 5 November 2018
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
.
Description: AutoSetOwner Condition: On Resolve Action: User Defined Custom action preparation code: return 1; Custom action cleanup code: \# get actor ID my $Actor = $self->TransactionObj->Creator;
\# if actor is RT_SystemUser then get out of here return 1 if $Actor == $RT::SystemUser->id;
\# prevents a ticket being assigned to an unprivileged user, comment out if you want this return 1 unless $self->TransactionObj->CreatorObj->Privileged;
\# get out unless ticket owner is nobody return 1 unless $self->TicketObj->Owner == $RT::Nobody->id;
\# ok, try to change owner $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; 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
A variation on this theme is AutoSetOwnerIfAdminCc
Another variation is AutoSetOwnerForQueue