[rt-users] How set a default value on Custom Field when Change Owner

Kenneth Crocker kfcrocker at lbl.gov
Tue Mar 1 12:08:38 EST 2011


Mauricio,

Try this:

Condition: Owner Change
Action: User-defined
Template: Global Blank
Stage: TransactionBatch

Custom Prep Code:
# set the CF Default value

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = "Tipo de Defacement";
my $cf_value = "Desfiguracao de Sitio";

$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,
RecordTransaction=>0);

return 1;

Custom Cleanup Code:
return 1;

This works for us.

Kenn
LBNL

On Tue, Mar 1, 2011 at 5:04 AM, <mauricio.leite at planalto.gov.br> wrote:

>  I made  a scrip to set a value on CF when changing owner, but is not
> working.
> Does somebody can help me.
> My code bellow:
>
> use RT::Ticket;
> use RT::CustomField;
> my $Ticket = $self->TicketObj;
> my $CFName = 'Tipo de Defacement';
> my $QueueObj = $Ticket->QueueObj;
> my $CFObj = RT::CustomField->new( $QueueObj->$self->CurrentUser );
> $CFObj->LoadByNameAndQueue( Name => $CFName, Queue => $QueueObj->id );
> $Ticket->AddCustomFieldValue(   Field => $CFObj->id,
>                                          Value => "Desfiguracao de Sitio",
>                                          RecordTransaction => 1);
> Thanks.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20110301/0f234203/attachment.htm>


More information about the rt-users mailing list