AutoSetOwner: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
(Added line to prevent a ticket being assigned to an unprivileged user.)
m (4 revisions imported)
(No difference)

Revision as of 15:03, 6 April 2016

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"

A variation on this theme is AutoSetOwnerIfAdminCc

Another variation is AutoSetOwnerForQueue