Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Request Tracker: Users

Scrip to automatically set Owner based on a Custom Field

 

 

Request Tracker users RSS feed   Index | Next | Previous | View Threaded


jrummel at imapp

Oct 29, 2009, 4:50 PM

Post #1 of 6 (1364 views)
Permalink
Scrip to automatically set Owner based on a Custom Field

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?

Thanks!
--
View this message in context: http://www.nabble.com/Scrip-to-automatically-set-Owner-based-on-a-Custom-Field-tp26122827p26122827.html
Sent from the Request Tracker - User mailing list archive at Nabble.com.

_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: sales [at] bestpractical


Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
Buy a copy at http://rtbook.bestpractical.com


elacour at easter-eggs

Oct 29, 2009, 11:59 PM

Post #2 of 6 (1293 views)
Permalink
Re: Scrip to automatically set Owner based on a Custom Field [In reply to]

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


Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
Buy a copy at http://rtbook.bestpractical.com


cgarcia at ific

Oct 30, 2009, 12:47 AM

Post #3 of 6 (1281 views)
Permalink
Re: Scrip to automatically set Owner based on a Custom Field [In reply to]

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
>
>
> 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
|C S I C| Apartado de Correos 22085 E-46071 Valencia Tel: +34 963543706
|_______| España / Spain Fax: +34 963543488
Attachments: cgarcia.vcf (0.43 KB)


kfcrocker at lbl

Oct 30, 2009, 8:56 AM

Post #4 of 6 (1278 views)
Permalink
Re: Scrip to automatically set Owner based on a Custom Field [In reply to]

Jrummel,

We do this for our queue that reviews requests. Based on the Org code,
we set the owner for the person best suited to evaluate tickets for that
organization. This is our code:

#----------------------------------------------------------------------------
# Custom action Preparation Code:
#----------------------------------------------------------------------------
#
# set new ticket owner id value
#
# 42 - Frank
# 148 - Bob
# 5125 - Sally
# 9324 - Roberta
# 73886 - Ted
#

my %orgs = qw(
Budget-Direct 148
Budget-Indirect 148
Controller-AP 5125
Controller-AR 73886
Controller-GA 148
Controller-PR 42
Facilities 42
Field OPS 42
OCFO-Other 42
Procurement 9324
Property 9324
SPO 73886
Travel 5125
Other 42
);

my $cf = new RT::CustomField($RT::SystemUser);
$cf->LoadByName(Queue => $ticket->QueueObj->id,Name => "CFO-Org");
return 0 unless $cf->id;
my $cfvalue = $ticket->FirstCustomFieldValue('CFO-Org');
my $ownerid = $orgs{$cfvalue};

# set Ticket Due date & Owner ID

$ticket->SetOwner($ownerid);

return 1;
#----------------------------------------------------------------------------
# Custom action Cleanup Code:
#----------------------------------------------------------------------------

return 1;

I hope this helps.

Kenn
LBNL

On 10/29/2009 4:50 PM, 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?
>
> Thanks!
>
_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: sales [at] bestpractical


Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
Buy a copy at http://rtbook.bestpractical.com


jrummel at imapp

Oct 30, 2009, 12:23 PM

Post #5 of 6 (1279 views)
Permalink
Re: Scrip to automatically set Owner based on a Custom Field [In reply to]

Thank you all so much for your time. I got it to work!

Expanding on it further:

Say I have 40 products, and 5 users. Each of these 5 users works on more
than one product.

Would I then have to make 5 different scrips with "OR" statements in them?
Ideally, I would like to be able to add a column to the CustomFieldValues
table containing a value of 1-5. Then make a small table called UserOwner
or something with 2 columns:

one column with values 1-5 called "id" (relating to the added column in
CustomFieldValues), and one column with usernames called "Name".

I guess that's a long way of asking if there is a way to accomplish this in
1 scrip by way of an SQL statement? Hopefully I explained that somewhat
coherently.

Thanks again!



Carlos Garcia Montoro wrote:
>
> 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
>>
>>
>> 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
> |C S I C| Apartado de Correos 22085 E-46071 Valencia Tel: +34 963543706
> |_______| España / Spain Fax: +34 963543488
>
> begin:vcard
> fn;quoted-printable:Carlos Garc=C3=ADa Montoro
> n;quoted-printable:Garc=C3=ADa Montoro;Carlos
> org;quoted-printable;quoted-printable:Instituto de F=C3=ADsica
> Corpuscular;Servicios Inform=C3=A1ticos
> adr;quoted-printable:Apartado de Correos 22085;;Edificio Institutos de
> Investigaci=C3=B3n;Valencia;Valencia;E-46071;Spain
> email;internet:Carlos.Garcia [at] ific
> tel;work:(+34) 96 354 37 06
> x-mozilla-html:TRUE
> version:2.1
> end:vcard
>
>
> _______________________________________________
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>
> Community help: http://wiki.bestpractical.com
> Commercial support: sales [at] bestpractical
>
>
> Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
> Buy a copy at http://rtbook.bestpractical.com
>

--
View this message in context: http://old.nabble.com/Scrip-to-automatically-set-Owner-based-on-a-Custom-Field-tp26122827p26135648.html
Sent from the Request Tracker - User mailing list archive at Nabble.com.

_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: sales [at] bestpractical


Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
Buy a copy at http://rtbook.bestpractical.com


kfcrocker at lbl

Oct 30, 2009, 2:04 PM

Post #6 of 6 (1267 views)
Permalink
Re: Scrip to automatically set Owner based on a Custom Field [In reply to]

Jrummel,

Again, look at the code I sent you. In it you have on a few users
working on more than one ORG code. Set up a qw( .... ...) with your
values and you're set.

Kenn
LBNL

On 10/30/2009 12:23 PM, jrummel wrote:
> Thank you all so much for your time. I got it to work!
>
> Expanding on it further:
>
> Say I have 40 products, and 5 users. Each of these 5 users works on more
> than one product.
>
> Would I then have to make 5 different scrips with "OR" statements in them?
> Ideally, I would like to be able to add a column to the CustomFieldValues
> table containing a value of 1-5. Then make a small table called UserOwner
> or something with 2 columns:
>
> one column with values 1-5 called "id" (relating to the added column in
> CustomFieldValues), and one column with usernames called "Name".
>
> I guess that's a long way of asking if there is a way to accomplish this in
> 1 scrip by way of an SQL statement? Hopefully I explained that somewhat
> coherently.
>
> Thanks again!
>
>
>
> Carlos Garcia Montoro wrote:
>
>> 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
>>>
>>>
>>> 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
>> |C S I C| Apartado de Correos 22085 E-46071 Valencia Tel: +34 963543706
>> |_______| España / Spain Fax: +34 963543488
>>
>> begin:vcard
>> fn;quoted-printable:Carlos Garc=C3=ADa Montoro
>> n;quoted-printable:Garc=C3=ADa Montoro;Carlos
>> org;quoted-printable;quoted-printable:Instituto de F=C3=ADsica
>> Corpuscular;Servicios Inform=C3=A1ticos
>> adr;quoted-printable:Apartado de Correos 22085;;Edificio Institutos de
>> Investigaci=C3=B3n;Valencia;Valencia;E-46071;Spain
>> email;internet:Carlos.Garcia [at] ific
>> tel;work:(+34) 96 354 37 06
>> x-mozilla-html:TRUE
>> version:2.1
>> end:vcard
>>
>>
>> _______________________________________________
>> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>>
>> Community help: http://wiki.bestpractical.com
>> Commercial support: sales [at] bestpractical
>>
>>
>> Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
>> Buy a copy at http://rtbook.bestpractical.com
>>
>>
>
>

Request Tracker users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.