[rt-users] Autofill custom fields
Rodney Rindels
rrindels at gmail.com
Wed Apr 19 11:43:56 EDT 2006
On 4/19/06, spydrrrrr at gmail.com <spydrrrrr at gmail.com> 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;
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20060419/094d504e/attachment.htm>
More information about the rt-users
mailing list