[rt-users] Scrip to automatically set Owner based on a Custom Field

Carlos Garcia Montoro cgarcia at ific.uv.es
Fri Oct 30 03:47:47 EDT 2009


I did something similar. If the custom field had a particular value, 
then the owner had to be a particular user. I did it using this scrip:

Custom condition:

if ($self->TransactionObj->Type eq 'Create' &&
     $self->TicketObj->FirstCustomFieldValue('Product') eq 'Product A') {
     return 1;
}
return 0;

Custom Action:
$self->TicketObj->SetOwner('John Smith');
return 1;

Hope it helps,
Carlos

Emmanuel Lacour wrote:
> On Thu, Oct 29, 2009 at 04:50:47PM -0700, jrummel wrote:
>> Hi everyone,
>>
>> I have a select-one Custom Field called "Product" with 5 products in it. 
>> Based on what product is selected (on create), I would like a specific user
>> to be set as the Owner (ex: ticket is created with "Product A" selected, so
>> John Smith works on Product A, thus should automatically be the Owner). 
>> Does anyone know the what my Custom Action would look like to accomplish
>> this?
>>
> 
> 
> You should use two customfields, one ticket customfield used to set the
> product for the ticket, another _user_ customfield to set the list of
> product a user works on in the user profile. Then your action will
> compare those values and set the owner.
> 
> Here is a not tested code to help you:
> 
> my $Ticket = $self->TicketObj;
> 
> # Get products selected for this ticket
> my $T_product = $Ticket->FirstCustomFieldValue ( 'Product' );
> 
> # Try to find a User with this product
> my $user_found = undef;
> my $Users = RT::Users->new ( $RT::SystemUser );
> while ( my $User = $Users->Next () )
> {
>         my $U_products = $User->CustomFieldValues ( 'Products' );
>         while ( my $product = $U_products->Next )
>         {       
>                 if ( $product->Content eq $T_product )
>                 {       
>                     $user_found = $User;
>                     last;
>                 }       
>         }       
> }
> 
> if ( $user_found && $user_found->Id ) {
>     $RT::Logger->debug("User ".$user_found->Name." found for product ".$T_product." Ticket ".$Ticket->Id );
>     $Ticket->SetOwner( $user_found );
> } else {
>     return 0;
> }
> 
> return 1;
> 
> _______________________________________________
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
> 
> Community help: http://wiki.bestpractical.com
> Commercial support: sales at bestpractical.com
> 
> 
> Discover RT's hidden secrets with RT Essentials from O'Reilly Media. 
> Buy a copy at http://rtbook.bestpractical.com
> 

-- 
  _______ _______________________________________________________________
| __ __ | Carlos García Montoro                    Ingeniero Informático
|_\_Y_/_| Instituto de Física Corpuscular         Centro Mixto CSIC - UV
|\_] [_/| Servicios Informáticos
|  [_]  | Edificio Institutos de Investigación        cgarcia at ific.uv.es
|C S I C| Apartado de Correos 22085 E-46071 Valencia  Tel: +34 963543706
|_______| España / Spain                              Fax: +34 963543488
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cgarcia.vcf
Type: text/x-vcard
Size: 441 bytes
Desc: not available
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20091030/f0e2dc1c/attachment.vcf>


More information about the rt-users mailing list