Custom Condition using a CustomField

I’d like to detect the value of a CustomField and add a value to the
CCs field based on the CustomField’s value in the newly created
ticket.

To experiment with a user defined condition on an existing field, I
successfully used the following:

Description: TestCreate
Condition: User Defined
Custom Condition:
use RT::CurrentUser;
my $User = new RT::CurrentUser();
$User->Load($self->TicketObj->Creator);
if (($self->TransactionObj->Type eq “Create”) and
($self->TicketObj->Subject =~ /testing/i)) {
return(1);
} else {
return(undef);
}

Action: Notify Requestors, CCs and AdminCCs
prep:
cleanup:
Template: TestOnCreate

This works and happily fires off an e-mail using the TestOnCreate
template when I use a subject with the word “testing” in it.

The goal I’m looking for is:

if CustomField-40 = “somevalue"
push CCs array, "test@example.com

One of the snippets I’ve tried is this code in the CustomCondition
field:

 use RT::CurrentUser;
 use RT::CustomField;
 my $User = new RT::CurrentUser();
 my $CustomFieldObj = RT::CustomField->new($User{'CurrentUser'});

 $User->Load($self->TicketObj->Creator);
 if (($self->TransactionObj->Type eq "Create") and 
    ($self->TicketObj->CustomField-40 =~ /GWI/i)) {
    return(1);
 } else {
    return(undef);
 }

But it yields the following error in the log:

[Fri Feb 6 20:33:02 2004] [error]: Scrip 93 IsApplicable failed:
Global symbol “%User” requires explicit package name at (eval 1983)
line 4.

(/usr/local/rt3/lib/RT/Condition/UserDefined.pm:45)

Any help would be appreciated. Thanx!

Andy Harrison
(full headers for details)

Andy Harrison wrote:

I’d like to detect the value of a CustomField and add a value to the
CCs field based on the CustomField’s value in the newly created
ticket.

To experiment with a user defined condition on an existing field, I
successfully used the following:

Description: TestCreate
Condition: User Defined
Custom Condition:
use RT::CurrentUser;
throw it to the bin, you don’t need any f* with current user as I think.
RT has $RT::SystemUser which is SU and offer full control over thing, I
don’t think you want check permissions.
my $User = new RT::CurrentUser();
$User->Load($self->TicketObj->Creator);
if (($self->TransactionObj->Type eq “Create”) and
($self->TicketObj->Subject =~ /testing/i)) {
return(1);
} else {
return(undef);
}

Action: Notify Requestors, CCs and AdminCCs
prep:
cleanup:
Template: TestOnCreate

This works and happily fires off an e-mail using the TestOnCreate
template when I use a subject with the word “testing” in it.

The goal I’m looking for is:

if CustomField-40 = “somevalue"
push CCs array, "test@example.com

One of the snippets I’ve tried is this code in the CustomCondition
field:

 use RT::CurrentUser;
 use RT::CustomField;
 my $User = new RT::CurrentUser();
 my $CustomFieldObj = RT::CustomField->new($User{'CurrentUser'});

 $User->Load($self->TicketObj->Creator);
 if (($self->TransactionObj->Type eq "Create") and 
    ($self->TicketObj->CustomField-40 =~ /GWI/i)) {
    return(1);
 } else {
    return(undef);
 }

return undef unless ($self->TransactionObj->Type eq “Create”);
return undef unless ($self->TicketObj->FirstCustomFieldValue(‘mycf’) =~
/GWI/i);
return 1;

But it yields the following error in the log:

[Fri Feb 6 20:33:02 2004] [error]: Scrip 93 IsApplicable failed:
Global symbol “%User” requires explicit package name at (eval 1983)
line 4.
Error means:
You don’t have defined hash with name User, it’s true because you have
$User - blessed scalar referense to RT::User instance.

perldoc perltoot

return undef unless ($self->TransactionObj->Type eq “Create”);
return undef unless ($self->TicketObj->FirstCustomFieldValue(‘mycf’) =~
/GWI/i);
return 1;

Very cool. Cutting it down to just these three lines did the trick.

One more question because I’ve never done a custom action.

I want to use “Notify Requestors and Ccs” but also
push(@{$self->{‘Cc’}}, ‘foo@example.com’);

How can I do this?

Andy Harrison
(full headers for details)

One more question because I’ve never done a custom action.

I want to use “Notify Requestors and Ccs” but also
push(@{$self->{‘Cc’}}, ‘foo@example.com’);

How can I do this?

In trying to answer my own question, this is one of the things I’m
trying:

Condition: User Defined
Custom Condition:

return undef unless ($self->TransactionObj->Type eq “Create”);
return undef unless ($self->TicketObj->FirstCustomFieldValue(‘Domain’) =~
/GWI/i); return 1;

Action: User Defined
prep: 1;
commit:

$self->TicketObj->AddWatcher{ TYPE => ‘Cc’, Email =>
‘test@example.com’ };

template: TestOnCreate

This gives me errors like:

[Tue Feb 10 14:04:58 2004] [error]: Scrip 93 Commit failed: syntax
error at (eval 2184) line 2, near "->AddWatcher{ "
(/usr/local/rt3/lib/RT/Action/UserDefined.pm:59)

Could anyone shed some light on this?

Andy Harrison
(full headers for details)

  • Andy Harrison [2004/02/10 09:33]:

This [code] gives me errors like:

[Tue Feb 10 14:04:58 2004] [error]: Scrip 93 Commit failed: syntax
error at (eval 2184) line 2, near "->AddWatcher{ "
(/usr/local/rt3/lib/RT/Action/UserDefined.pm:59)

Could anyone shed some light on this?

Perl syntax error. Try:

$self->TicketObj->AddWatcher( TYPE => ‘Cc’, Email => ‘test@example.com’ );

I.e., ( ) instead of { }.

(darren)

How is it possible to find meaning in a finite world, given my waist
and shirt size?
– Woody Allen

Perl syntax error. Try:

$self->TicketObj->AddWatcher( TYPE => ‘Cc’, Email => ‘test@example.com’ );

I.e., ( ) instead of { }.

(darren)

DOH…

I changed it. The other thing I was stupidly doing was TYPE instead
of Type. It’s actually working now.

But, how do I get the action to add the watcher and then send out the
e-mail in one fell swoop?

If this can’t be done and requires another On Create action, how can I
make sure that one scrip with the same condition is executed before
another?

Andy Harrison
(full headers for details)

Aside from my previous question, I’d also like to detect the value of
a CustomField and add a value to the CCs field based on the
CustomField’s value in the newly created ticket.

To experiment with a user defined condition on an existing field, I
successfully used the following:

Description: TestCreate
Condition: User Defined
Custom Condition:
use RT::CurrentUser;
my $User = new RT::CurrentUser();
$User->Load($self->TicketObj->Creator);
if (($self->TransactionObj->Type eq “Create”) and
($self->TicketObj->Subject =~ /testing/i)) {
return(1);
} else {
return(undef);
}

Action: Notify Requestors, CCs and AdminCCs
prep:
cleanup:
Template: TestOnCreate

This works and happily fires off an e-mail using the TestOnCreate
template that I created just for this one test.

The goal I’m looking for is:

if CustomField-40 = “somevalue"
push CCs array, "test@example.com

I’m currently trying this in the CustomCondition field:

use RT::CurrentUser;
use RT::CustomField;
my $User = new RT::CurrentUser();
my $CustomFieldObj = RT::CustomField->new($User{'CurrentUser'});

$User->Load($self->TicketObj->Creator);
if (($self->TransactionObj->Type eq "Create") and 
   ($self->TicketObj->CustomField-40 =~ /GWI/i)) {
   return(1);
} else {
   return(undef);
}

But it yields the following error in the log:

[Fri Feb 6 20:33:02 2004] [error]: Scrip 93 IsApplicable failed:
Global symbol “%User” requires explicit package name at (eval 1983)
line 4.

(/usr/local/rt3/lib/RT/Condition/UserDefined.pm:45)

Any help would be appreciated. Thanx!

Andy Harrison
(full headers for details)