[rt-users] Default value's on creation

Bart bart at pleh.info
Wed Oct 12 03:11:46 EDT 2011


Thanks to the below scrip I've been able to get this work :-)

Though, the syntax is a little different:

if( ! $self->TicketObj-> FirstCustomFieldValue( 'Type' ) ) {
$self->TicketObj->AddCustomFieldValue(Field => 'Type', Value => 'Incident'
);
}

return 1;

This sets the Type to Incident when the CF is empty, but won't set the CF if
it's already filled.

Thanks for the tip.


-- Bart


2011/10/11 Gerard FENELON <gerard at eve-team.com>

>  Hi Bart
>
> we use
>
>   if( ! $ticket->CustomFieldValues( 'Software Ready' )->First )
>     {
>     # set the custom field
>     my $cf = RT::CustomField->new( $RT::SystemUser );
>     $cf->LoadByName( Name => 'Software Ready' );
>     my ( $status, $msg ) = $ticket->AddCustomFieldValue( Field => $cf,
> Value => 'Not ready' );
>
>     if( $status )
>       {
>       $RT::Logger->info( $blurb . " : 'Software Ready' set to 'Not ready'"
> );
>       }
>     else
>       {
>       $RT::Logger->warning( $blurb . " : Couldn't set 'Software Ready' to
> 'Not ready'" . $msg );
>       }
>     }
>
> Gerard
>
>
> On 2011-10-11 15:44, Bart wrote:
>
> Hi,
>
> I have a simple scrip that sets some default values during the creation of
> a ticket.
> The problem witht his scrip is that it's a little rough, it sets the values
> even when somoen manually creates a ticket and fills in the fields (they get
> overwritten).
>
> Because of that I want the scrip to first check if the field isn't set
> already, with that I'm kinda having a problem, checking if the field is NULL
> doesn't seem to work...
>
> What's the best way for checking if a Custom Field (in this case) isn't
> set?
>
> I've tried these options but they don't seem to work:
>
> Check if the field is empty:
>
> if($self->TicketObj->FirstCustomFieldValue(Field => 'Type') = 'NULL') { do
> something };
>
> Since this field could contain the option Problem this if statement does
> something when the ticket is set to Problem (for testing, but this doesn't
> seem to work either):
>
> if($self->TicketObj->FirstCustomFieldValue(Field => 'Type') =~ /^P/) { do
> something );
>
> And a bunch of varaiaties where I\ve either bumped against issues of syntax
> not being recognised, etc. (things like neq, !=, NULL without quotes, etc.).
>
> Does anyone have an example on how to do something similar? (check if a CF
> is empty, if so then fill it with a value)
>
> -- Bart
>
>
>
> --------
> RT Training Sessions (http://bestpractical.com/services/training.html)
> *  San Francisco, CA, USA — October 18 & 19, 2011
> *  Washington DC, USA — October 31 & November 1, 2011
> *  Barcelona, Spain — November 28 & 29, 2011
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20111012/cc06a08b/attachment.htm>


More information about the rt-users mailing list