<br><br><div><span class="gmail_quote">On 4/19/06, <b class="gmail_sendername"><a href="mailto:spydrrrrr@gmail.com">spydrrrrr@gmail.com</a></b> <<a href="mailto:spydrrrrr@gmail.com">spydrrrrr@gmail.com</a>> wrote:</span>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style="direction: ltr;">Does anyone have a code snippet for autofilling custom fields based on the entries of other custom fields?
<br>For instance say you have a custom field for Location Name: XXXX<br>Then address custom field would autfill based on the entry for Location Name...
<br><br>Jim</div></blockquote><div><br>Jim,<br><br>I would do something like this , although I'm sure there are more elegant solutions.<br>I added more than you would need to accomplish it to show how to get at certain bits.
<br><br>I use this in the Custom Action Cleanup with an On Transaction Scrip<br><br>Hope this helps, <br><br>Rodney<br><br>-----------------------------------------------------------------------------------------------------
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>#Define the Custom Field Names Were Going to Play with.<br>
my $CFName = 'Location Name;<br>
my $CFToChange = 'Address';<br>
<br>
#Transaction Association<br>
my $txnObj = $self->TransactionObj;<br>
<br>
my $ticketObj  = $self->TicketObj;<br>
<br>
my $queueObj   = $self->TicketObj->QueueObj;<br>
<br>
my $CFObj       = RT::CustomField->new($RT::SystemUser);<br>
my $CFNewObj = RT::CustomField->new($RT::SystemUser);<br>
<br>
#Grab the Custom Field were using for the switch.</div></blockquote><div><br>   #We dont necessarily need this, but hey here it is... <br></div><br><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="direction: ltr;">
$CFObj->LoadByNameAndQueue(Name => $CFName, Queue => $queueObj->id);<br>
   unless($CFObj->id) {<br>
       $CFObj->LoadByNameAndQueue(Name => $CFName, Queue=>0);<br>
       unless($CFObj->id){<br>
           $RT::Logger->warning("Custom Field: $CFName not for this Queue");<br>
           return undef;<br>
       };<br>
   }; <br>
<br>
#Grab the Custom Field we want to set.<br>
 $CFNewObj->LoadByNameAndQueue(Name => $CFToChange, Queue => $queueObj->id);<br>

   unless($CFNewObj->id) {<br>

       $CFNewObj->LoadByNameAndQueue(Name => $CFToChange, Queue=>0);<br>

       unless($CFNewObj->id){<br>

           $RT::Logger->warning("Custom Field: $CFToChange not for this Queue");<br>

           return undef;<br>

       };<br>

   }; <br>
<br>
my $cfv = $ticketObj->FirstCustomFieldValue($CFName);<br>
<br>
#ok lets set this..<br>
#Your relevant logic to determine what you want to set the address to here.......<br>
my $address = undef;<br>
if ($cfv eq 'Shop')<br>
{<br>
     $address = '4001 Pine Avenue';<br>
};<br>
<br>
my ($st, $msg) = $ticketObj->AddCustomFieldValue(<br>
                                 Field => $CFNewObj->id,<br>
                                 Value => $address,<br>
                                 RecordTransaction => 1<br>
                           );<br>
<br>
unless ($st){<br>
       $RT::Logger->warning("Odd we couldn't set $CFToChange to $address");<br>
};<br>
return 1;  </div></blockquote><div><br> </div><br></div><br>