Difference between revisions of "AutoSetOwner"

From Request Tracker Wiki
Jump to navigation Jump to search
(Added line to prevent a ticket being assigned to an unprivileged user.)
m
(2 intermediate revisions by 2 users not shown)
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-&gt;TransactionObj-&gt;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-&gt;id;<br />
   return 1 if $Actor == $RT::SystemUser-&gt;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-&gt;TicketObj-&gt;Owner == $RT::Nobody-&gt;id;<br />
   \# ok, try to change owner
   # get out unless ticket owner is nobody
   return 1 unless $self-&gt;TicketObj-&gt;Owner == $RT::Nobody-&gt;id;
   # ok, try to change owner
   $RT::Logger-&gt;info("Auto assign ticket #". $self-&gt;TicketObj-&gt;id ." to user #". $Actor );
   $RT::Logger-&gt;info("Auto assign ticket #". $self-&gt;TicketObj-&gt;id ." to user #". $Actor );
   my ($status, $msg) = $self-&gt;TicketObj-&gt;SetOwner( $Actor );
   my ($status, $msg) = $self-&gt;TicketObj-&gt;SetOwner( $Actor );
Line 41: Line 37:
<u>Changelog:</u>
<u>Changelog:</u>


  20050525/Rejo  Added "Condition" line
  '''20050525/Rejo''' Added "Condition" line
   
   
  20060105/HaimDimer Translated the remaning French into English.
  '''20060105/HaimDimer''' Translated the remaning French into English.<br />
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 04:45, 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