Search old tickets from within scrip

RT 3.6.1

We have one custom field per ticket, “Customer”, of type ‘select one
value’. So far, we’ve set that value manually on each new ticket, but I’d
like to automate it.

What I’d like to do, within a script, is search for the last ticket from
this requestor and set the customer custom field to the same value. In
pseudo SQL terms: “select customer from custom_fields where
requestor_address = ‘$requestor’ and customer != null order id desc limit
1”. How can I do that kind of search from a script? I’m not looking for
in-depth instructions, just a pointer as to the best way of doing this.

Thanks,
Keith

<<<
my $tickets = RT::Tickets->new( $RT::SystemUser );
$tickets->FromSQL(“Requestor.EmailAddress = ‘$address’ AND
‘CustomField.{Customer}’ IS NOT NULL”);

fetch from DB only first one ticket

$tickets->RowsPerPage(1);

my $ticket = $tickets->First;
return undef unless $ticket;

return $ticket->FirstCustomFieldValue(‘Customer’);

  • code not tested
  • I’m not sure if 3.6.1 supports ‘IS NOT NULL’ for CFs, but 3.6.latest should

I can suggest you another way with two scrips:

  1. Update Company field of requestors when an user update customer custom field
  2. On ticket create check if a requestor has defined Company property
    and update the fieldOn 8/8/07, Keith Edmunds kae@midnighthax.com wrote:

RT 3.6.1

We have one custom field per ticket, “Customer”, of type ‘select one
value’. So far, we’ve set that value manually on each new ticket, but I’d
like to automate it.

What I’d like to do, within a script, is search for the last ticket from
this requestor and set the customer custom field to the same value. In
pseudo SQL terms: “select customer from custom_fields where
requestor_address = ‘$requestor’ and customer != null order id desc limit
1”. How can I do that kind of search from a script? I’m not looking for
in-depth instructions, just a pointer as to the best way of doing this.

Thanks,
Keith


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

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

Best regards, Ruslan.

On Wed, 8 Aug 2007 03:26:21 +0400, ruz@bestpractical.com said:

I can suggest you another way with two scrips:

  1. Update Company field of requestors when an user update customer
    custom field

That’s a smart idea, but how does one access the requestor’s company field
(presumably “Organization”) from within a scrip? Sorry, my Perl is not
very good so a quick pointer would be appreciated.

Thanks,
Keith

$user_obj->Organisation; # returns value
$user_obj->SetOrganisation(‘new value’); # set new value

perldoc lib/RT/User.pm - basic accessors
perldoc lib/RT/User_Overlay.pm - more methodsOn 8/9/07, Keith Edmunds kae@midnighthax.com wrote:

On Wed, 8 Aug 2007 03:26:21 +0400, ruz@bestpractical.com said:

I can suggest you another way with two scrips:

  1. Update Company field of requestors when an user update customer
    custom field

That’s a smart idea, but how does one access the requestor’s company field
(presumably “Organization”) from within a scrip? Sorry, my Perl is not
very good so a quick pointer would be appreciated.

Thanks,
Keith


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

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

Best regards, Ruslan.