Script to test for keyword?

Hey there,

I’m putting together a custom scrip in rt2 to test for the existence of a
specific keyword value. This keyword is used to determine what kind of
notification is sent out when a ticket is opened. We have two release of
software within the same queue and they need different sorts of responses.
So for one, people get paged (Ccs) and for the other, people only get
emailed (AdminCcs).

Inserted into the database :

mysql> insert into ScripConditions set Name = “OnPhase1.5Create”,
Description = ‘Phase 1.5 keyword ticket created’,
ExecModule=‘phase15create’, ApplicableTransTypes = ‘Create’;

And the script is :

package RT::Condition::phase10create;
require RT::Condition::Generic;

@ISA = qw(RT::Condition::Generic);

=head2 IsApplicable

If the ticket contains the Phase/1.5 keyword return true

=cut

sub IsApplicable {
my $self = shift;
if ($self->TicketObj->KeywordSelect-2 eq ‘1.5’) {
return(1);
}
else {
return(undef);
}
}

KeywordSelect-2 is the index for that tree of keywords (Phase/1.0 and
Phase/1.5) in RT.

Does this look right, or am I smoking crack here ? So sorry if this is a
trivial question, try as I might I haven’t quite got there yet :slight_smile:

All help appreciated.

Cheers,

Al

  • Alan Horn [2003/12/08 15:30]:

sub IsApplicable {
my $self = shift;
if ($self->TicketObj->KeywordSelect-2 eq ‘1.5’) {
^^^^^^^^^^^^^^^

Perl identifiers are limited to alphanumics and underscores, so this
will be interpreted as:

if (($self->TicketObj->KeywordSelect) - 2) eq ‘1.5’) {

which is probablt not what you mean.

(darren)

When it is dark enough, you can see the stars.
– Ralph Waldo Emerson

Date: Tue, 9 Dec 2003 09:54:51 -0500
From: darren chamberlain darren@boston.com
To: rt-devel@lists.fsck.com
Subject: Re: [rt-devel] script to test for keyword ?

  • Alan Horn [2003/12/08 15:30]:

sub IsApplicable {
my $self = shift;
if ($self->TicketObj->KeywordSelect-2 eq ‘1.5’) {
^^^^^^^^^^^^^^^

Perl identifiers are limited to alphanumics and underscores, so this
will be interpreted as:

if (($self->TicketObj->KeywordSelect) - 2) eq ‘1.5’) {

which is probablt not what you mean.

(darren)

Looking more closely at the perldoc for Ticket, I realise that
KeywordSelect-2 is not a method (aside from the perl brokenness I put in
there :wink:

So, my question is, what method would I call to pull the keywords out of a
transaction ?

Cheers,

Al

Date: Tue, 9 Dec 2003 14:32:55 -0800 (PST)
From: Alan Horn ahorn@deorth.org
To: darren chamberlain darren@boston.com
Cc: rt-devel@lists.fsck.com
Subject: Re: [rt-devel] script to test for keyword ?

Date: Tue, 9 Dec 2003 09:54:51 -0500
From: darren chamberlain darren@boston.com
To: rt-devel@lists.fsck.com
Subject: Re: [rt-devel] script to test for keyword ?

  • Alan Horn [2003/12/08 15:30]:

sub IsApplicable {
my $self = shift;
if ($self->TicketObj->KeywordSelect-2 eq ‘1.5’) {
^^^^^^^^^^^^^^^

Perl identifiers are limited to alphanumics and underscores, so this
will be interpreted as:

if (($self->TicketObj->KeywordSelect) - 2) eq ‘1.5’) {

which is probablt not what you mean.

(darren)

Looking more closely at the perldoc for Ticket, I realise that
KeywordSelect-2 is not a method (aside from the perl brokenness I put in
there :wink:

So, my question is, what method would I call to pull the keywords out of a
transaction ?

Wel, after much head banging I finally came up with this :

sub IsApplicable {
my $self = shift;
## 2 is the ‘Phase’ keyword in KeywordSelects table
my $SELECTID = 2;
## 7 is the number for 1.0
my $CHILDID = 7;
if ($self->TicketObj->KeywordsObj($SELECTID)->HasEntry($CHILDID)) {
return(1);
}
else {
return(undef);
}
}

Which is a pretty non portable way to do it I guess… I have a separate
scrip for CHILDID = 8 (the other descendant of phase), and a third scrip
for the case where neither keyword is selected (to provide a suitable
default action)

I’m also very worried about the HasEntry method, since it’s from a module
that is outside the API and shouldn’t be used.

Is this a reasonable way to be going about this do you think ? Is there a
cleaner or more general approach ?

Cheers,

Al

p.s. all my earlier head banging was due to the HTML being borked (I’d
moved the keywords box… or rather… I hadn’t really… there were two
copies of it and the one on the ‘Details’ page of Create.html was
overriding and wiping out my selections)

A duh moment… :slight_smile: