[rt-users] Set CustomField value on 'Quick ticket creation'

Jim Meyer purp at acm.org
Mon Feb 6 21:07:26 EST 2006


On Mon, 2006-02-06 at 17:58 +0800, Stephen Fung wrote:
> Is it possible to set the value of a global custom field by using the 
> 'Quick ticket creation' form?
> I've modified the form to show that custom field but I found the custom 
> field is not updated while the ticket is created.

I'd toss those modifications and make a scrip (either global or for that
queue only) which on ticket creation (OnCreate) uses the user-defined
bits to set the proper value. You can access the Custom Field from
within the TicketObj like so:

my $cf_name = 'My Custom Field';
my $default_value = 'Foo';

my $queue_obj = $self->TicketObj->QueueObj;
my $cf_obj = RT::CustomField->new($queue_obj->CurrentUser);
$cf_obj->LoadByNameAndQueue(Name => $cf_name, 
                            Queue => $queue_obj->id);
unless( $cf_obj->id ) {
  $RT::Logger->warning("$cf_name doesn't exist for Queue ". 
  return undef;

# Get the first CF value for this ticket/field combo
my $cf_val = $self->TicketObj->FirstCustomFieldValue($cf_obj->id);

# Set the CF value
my($st, $msg) = 
        Field => $cf_obj->id,
        Value => $default_value,
        RecordTransaction =>1                    

Credit for this bit of code goes to my cohort, Russell Dumornay, who
puzzled out what was needed to do this trick.


Jim Meyer, Geek at Large                                    purp at acm.org

More information about the rt-users mailing list