[rt-users] Setting Custom field on create

Ken Crocker kfcrocker at lbl.gov
Fri Jul 10 11:52:29 EDT 2009


Chris,

We do this all the time. Try this:

******************* Custom Condition **********************
return ($self->TransactionObj->Type eq "Create" &&
           $self->TransactionObj->CreatorObj->Id(1101));

******************* Custom Prep Code *********************
my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = "Severity";
my $cf_value = "3";

$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 );

******************* Custom Cleanup Code *********************
return 1;

Hope this helps.

Kenn
LBNL

On 7/9/2009 3:33 PM, Chris Collison wrote:
> What I'm trying to do:
>
> When a specific user, id=1101 sends a request to RT I want it to 
> create the ticket as normal, but also set a custom field during the 
> creations process, ie the Severity custom field.  Tickets from this 
> specific user, 1101, will always be assigned the same severity value 
> of 3. The scrip to do this seems pretty simple.  The custom field is a 
> select type, and normally a user creates the ticket on RT webUI and 
> just selects this from the list.  Now we have requests being emailed 
> and need to set the custom field during the creation process.  I 
> didn't create the custom field, but it looks like this:
>
> Select 1 value:
> 1 Urgent - blahblah
> 2 High - blahblah
> 3 Medium - blahblah
> 4 Low - blahblah
>
> blahblah being the description of each
> Custom Condition:
> #############################
> my $transaction = $self->TransactionObj;
> my $ticket = $self->TicketObj;
>
> if (($transaction->Type eq 'Create') &&
>     ($ticket->Creator == 1101))
> {
>     return(1);
> }
> else
> {
>     return(0);
> }
> #############################
>
> Custom Action:
> #############################
> $Ticket->FirstCustomFieldValue('Severity') = '3'
>
>
> #############################
> This doesn't work. Also tried setting it as '3 Medium - blahblah'.  It 
> seems that this isn't the way to set the customfield.
>
> After reading some posts on here it appears I have to create a custom 
> field by hand and set it somehow.
>
> Something like:
>
> my $cf = new RT::CustomField($RT::SystemUser);
> $cf = '3 Medium blahblah'
> #set a transaction object of type 'CustomField' to the value of $cf?
>
>
> Is this how I would go about doing it? Am I on the right track here? 
> Any help would be appreciated!
>
>
>
>
> ~Chris
>
>
> ------------------------------------------------------------------------
> Lauren found her dream laptop. Find the PC that’s right for you. 
> <http://www.microsoft.com/windows/choosepc/?ocid=ftp_val_wl_290>
> ------------------------------------------------------------------------
>
> _______________________________________________
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>
> Community help: http://wiki.bestpractical.com
> Commercial support: sales at bestpractical.com
>
>
> Discover RT's hidden secrets with RT Essentials from O'Reilly Media. 
> Buy a copy at http://rtbook.bestpractical.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20090710/1753fc44/attachment.htm>


More information about the rt-users mailing list