Scrip not working

To all,

I need some help with a scrip. I have the following coded:

Custom condition:

Check for ticket status changed to “open”

my $trans = $self->TransactionObj;

return ($trans->Type eq “Status” &&
$trans->NewValue eq “open”);

Custom action preparation code:

set new Work-Status value

my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = “Work-Status”;
my $cf_value = “Estimating Effort”;

$cf_obj->LoadByName( Name => $cf_name );
$RT::Logger->debug( “Loaded $cf_obj->Name = “. $cf_obj->Name() .”\n” );
$cf_obj->AddValueForObject( Object=>$ticket, Content=>$cf_value, );

return 1;

Custom action cleanup code: None

When I change the ticket status to "open", nothing happens. I do have a 

notification scrip that produces an E_mail notification based on the
same user-defined condition and that works. But nothing else is getting
done. Any ideas as to why? I have another scrip similar to this one
(different Custom field modified and for only 1 particulat queue) and it
doesn’t work either. Thanks in advance.

Kenn
LBNL

Kenneth Crocker wrote:

To all,

I need some help with a scrip. I have the following coded:

#----------------------------------------------------------------------------

Custom action preparation code:

#----------------------------------------------------------------------------

set new Work-Status value

my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = “Work-Status”;
my $cf_value = “Estimating Effort”;

$cf_obj->LoadByName( Name => $cf_name );
$RT::Logger->debug( “Loaded $cf_obj->Name = “. $cf_obj->Name() .”\n” );
$cf_obj->AddValueForObject( Object=>$ticket, Content=>$cf_value, );
I don’t have any experience in Perl coding but check the last line. Is
it possible that there’s the error? There is no parameter behind the
last comma or the comma itself is to much maybe…

Regards,
Ben

Hi Kenn,

Here’s how I’d do it using my the set_custom function I use in my scrips:

set_custom(“Work-Status”, “Estimating Effort”);

Sets custom field value

Usage: set_custom($field_name, $field_value, $record_transaction)

sub set_custom {
my ($CFName, $CFValue, $record) = @_;
my $cf = RT::CustomField->new($RT::SystemUser);
my ($id,$msg) = $cf->LoadByName(Name=>$CFName,);
if (!$id) {
$RT::Logger->debug("$MyName: Couldn’t load CF ($CFName)");
return undef;
}
($id, $msg) = $Ticket->AddCustomFieldValue
(Field=>$cf, Value=>$CFValue, RecordTransaction=>$record ? $record : 0);
}

It uses the AddCustomFieldValue method instead of
AddValueForObject. $record is 1 if you want the change to generate another
transaction, 0 otherwise.

Gene

At 07:58 AM 9/4/2007, Kenneth Crocker wrote:

$cf_obj->LoadByName( Name => $cf_name );
$RT::Logger->debug( “Loaded $cf_obj->Name = “. $cf_obj->Name() .”\n” );
$cf_obj->AddValueForObject( Object=>$ticket, Content=>$cf_value, );

return 1;

    When I change the ticket status to "open", nothing happens. I do 

have a notification scrip that produces an E_mail notification based on
the same user-defined condition and that works. But nothing else is
getting done. Any ideas as to why? I have another scrip similar to this
one (different Custom field modified and for only 1 particulat queue) and
it doesn’t work either. Thanks in advance.

Gene LeDuc, GSEC
Security Analyst
San Diego State University

Benjamin,

No, I have that in several scrips that ARE working. Thanks anyway.

Kenn
LBNLOn 9/4/2007 8:48 AM, Benjamin Weser wrote:

Kenneth Crocker wrote:

To all,

I need some help with a scrip. I have the following coded:

#----------------------------------------------------------------------------

Custom action preparation code:

#----------------------------------------------------------------------------

set new Work-Status value

my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = “Work-Status”;
my $cf_value = “Estimating Effort”;

$cf_obj->LoadByName( Name => $cf_name );
$RT::Logger->debug( “Loaded $cf_obj->Name = “. $cf_obj->Name() .”\n” );
$cf_obj->AddValueForObject( Object=>$ticket, Content=>$cf_value, );
I don’t have any experience in Perl coding but check the last line. Is
it possible that there’s the error? There is no parameter behind the
last comma or the comma itself is to much maybe…

Regards,
Ben

Gene,

I tried to modify my scrip with some of your code (I don't like 

subroutines) and it looks like this:

set new Work-Status value

my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = “Work-Status”;
my $cf_value = “Estimating Effort”;

$cf_obj->LoadByName(Name=>$cf_name);
$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n”);
$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$cf_value, );

return 1;

When executed, this is what I got:

 *  Ticket 54343: Status changed from 'new' to 'open'
 * Work-Status Estimating Effort changed to Requested

Why does the results say it changed the custom field to the value it 

USED to be? It acts like it is doing the work correctly, then reverses
itself. I don’t get it.

Kenn
LBNLOn 9/4/2007 8:47 AM, Gene LeDuc wrote:

Hi Kenn,

Here’s how I’d do it using my the set_custom function I use in my scrips:

set_custom(“Work-Status”, “Estimating Effort”);

Sets custom field value

Usage: set_custom($field_name, $field_value, $record_transaction)

sub set_custom {
my ($CFName, $CFValue, $record) = @_;
my $cf = RT::CustomField->new($RT::SystemUser);
my ($id,$msg) = $cf->LoadByName(Name=>$CFName,);
if (!$id) {
$RT::Logger->debug("$MyName: Couldn’t load CF ($CFName)");
return undef;
}
($id, $msg) = $Ticket->AddCustomFieldValue
(Field=>$cf, Value=>$CFValue, RecordTransaction=>$record ? $record
: 0);
}

It uses the AddCustomFieldValue method instead of AddValueForObject.
$record is 1 if you want the change to generate another transaction, 0
otherwise.

Gene

At 07:58 AM 9/4/2007, Kenneth Crocker wrote:

$cf_obj->LoadByName( Name => $cf_name );
$RT::Logger->debug( “Loaded $cf_obj->Name = “. $cf_obj->Name() .”\n” );
$cf_obj->AddValueForObject( Object=>$ticket, Content=>$cf_value, );

return 1;

    When I change the ticket status to "open", nothing happens. I 

do have a notification scrip that produces an E_mail notification
based on the same user-defined condition and that works. But nothing
else is getting done. Any ideas as to why? I have another scrip
similar to this one (different Custom field modified and for only 1
particulat queue) and it doesn’t work either. Thanks in advance.