Thanks to the below scrip I've been able to get this work :-)<div><br></div><div>Though, the syntax is a little different:</div><div><br></div><div><div><font class="Apple-style-span" face="'courier new', monospace">if( ! $self->TicketObj-> FirstCustomFieldValue( 'Type' ) ) {</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>$self->TicketObj->AddCustomFieldValue(Field => 'Type', Value => 'Incident' );</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>}</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace">return 1;</font></div><div><br></div><div>This sets the Type to Incident when the CF is empty, but won't set the CF if it's already filled.</div>
<div><br></div><div>Thanks for the tip.</div><div><br></div><div><br clear="all">-- Bart<br>
<br><br><div class="gmail_quote">2011/10/11 Gerard FENELON <span dir="ltr"><<a href="mailto:gerard@eve-team.com">gerard@eve-team.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div bgcolor="#FFFFFF" text="#000000">
<tt>Hi Bart<br>
<br>
we use<br>
<br>
if( ! $ticket->CustomFieldValues( 'Software Ready'
)->First )<br>
{<br>
# set the custom field<br>
my $cf = RT::CustomField->new( $RT::SystemUser );<br>
$cf->LoadByName( Name => 'Software Ready' );<br>
my ( $status, $msg ) = $ticket->AddCustomFieldValue( Field
=> $cf, Value => 'Not ready' );<br>
<br>
if( $status ) <br>
{<br>
$RT::Logger->info( $blurb . " : 'Software Ready' set to
'Not ready'" );<br>
}<br>
else<br>
{<br>
$RT::Logger->warning( $blurb . " : Couldn't set 'Software
Ready' to 'Not ready'" . $msg );<br>
}<br>
}<br>
<br>
</tt><font color="#888888">Gerard</font><div><div></div><div class="h5"><br>
<br>
On 2011-10-11 15:44, Bart wrote:
<blockquote type="cite">Hi,<br>
<br>
I have a simple scrip that sets some default values during the
creation of a ticket.<br>
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).<br>
<br>
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...<br>
<br>
What's the best way for checking if a Custom Field (in this case)
isn't set?<br>
<br>
I've tried these options but they don't seem to work:<br>
<br>
Check if the field is empty:<br>
<br>
<span style="font-family:courier new,monospace">if($self->TicketObj->FirstCustomFieldValue(Field
=> 'Type') = 'NULL') { do something };</span><br>
<br>
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):<br>
<br>
<span style="font-family:courier new,monospace">if($self->TicketObj->FirstCustomFieldValue(Field
=> 'Type') =~ /^P/) { do something );</span><br>
<br>
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.).<br>
<br>
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)<br>
<br clear="all">
-- Bart<br>
</blockquote>
<br>
</div></div></div>
<br>--------<br>
RT Training Sessions (<a href="http://bestpractical.com/services/training.html" target="_blank">http://bestpractical.com/services/training.html</a>)<br>
* San Francisco, CA, USA — October 18 & 19, 2011<br>
* Washington DC, USA — October 31 & November 1, 2011<br>
* Barcelona, Spain — November 28 & 29, 2011<br></blockquote></div><br></div></div>