On 4/19/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Does anyone have a code snippet for autofilling custom fields based on the entries of other custom fields?
For instance say you have a custom field for Location Name: XXXX
Then address custom field would autfill based on the entry for Location Name...

Jim

Jim,

I would do something like this , although I'm sure there are more elegant solutions.
I added more than you would need to accomplish it to show how to get at certain bits.

I use this in the Custom Action Cleanup with an On Transaction Scrip

Hope this helps,

Rodney

-----------------------------------------------------------------------------------------------------

#Define the Custom Field Names Were Going to Play with.
my $CFName = 'Location Name;
my $CFToChange = 'Address';

#Transaction Association
my $txnObj = $self->TransactionObj;

my $ticketObj  = $self->TicketObj;

my $queueObj   = $self->TicketObj->QueueObj;

my $CFObj       = RT::CustomField->new($RT::SystemUser);
my $CFNewObj = RT::CustomField->new($RT::SystemUser);

#Grab the Custom Field were using for the switch.

   #We dont necessarily need this, but hey here it is...


$CFObj->LoadByNameAndQueue(Name => $CFName, Queue => $queueObj->id);
   unless($CFObj->id) {
       $CFObj->LoadByNameAndQueue(Name => $CFName, Queue=>0);
       unless($CFObj->id){
           $RT::Logger->warning("Custom Field: $CFName not for this Queue");
           return undef;
       };
   };

#Grab the Custom Field we want to set.
 $CFNewObj->LoadByNameAndQueue(Name => $CFToChange, Queue => $queueObj->id);
   unless($CFNewObj->id) {
       $CFNewObj->LoadByNameAndQueue(Name => $CFToChange, Queue=>0);
       unless($CFNewObj->id){
           $RT::Logger->warning("Custom Field: $CFToChange not for this Queue");
           return undef;
       };
   };

my $cfv = $ticketObj->FirstCustomFieldValue($CFName);

#ok lets set this..
#Your relevant logic to determine what you want to set the address to here.......
my $address = undef;
if ($cfv eq 'Shop')
{
     $address = '4001 Pine Avenue';
};

my ($st, $msg) = $ticketObj->AddCustomFieldValue(
                                 Field => $CFNewObj->id,
                                 Value => $address,
                                 RecordTransaction => 1
                           );

unless ($st){
       $RT::Logger->warning("Odd we couldn't set $CFToChange to $address");
};
return 1; 

 


_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: [EMAIL PROTECTED]


Discover RT's hidden secrets with RT Essentials from O'Reilly Media. 
Buy a copy at http://rtbook.bestpractical.com


We're hiring! Come hack Perl for Best Practical: 
http://bestpractical.com/about/jobs.html

Reply via email to