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
LBNL

On 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.


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

Community help: http://wiki.bestpractical.com
Commercial support: [EMAIL PROTECTED]


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

Reply via email to