Hi Matt 

We solved it by using a Custom Field, which is populated every night by a 
cronjob. The cronjob script parses a specific Asset Type, ie Customer, and 
populates a CF named Customer. 

There's a Scrip which creates a link to the Asset automatically when creating a 
new ticket. 

It works great, but may not be as pretty :) 

I've attached everything for you here. Hope it works out for you. 

Btw. we're using RT 3.6.5. 

cronjob 
#!/usr/bin/perl 

use warnings; 
use strict; 

use lib qw(/opt/rt3/local/lib /opt/rt3/lib); 
use Getopt::Long; 

use RT; 
use RTx::AssetTracker; 
use RTx::AssetTracker::Assets; 
use RTx::AssetTracker::Asset; 
use RTx::AssetTracker::Types; 
use RTx::AssetTracker::Type; 
RT::LoadConfig(); 
RT::Init(); 

my %args; 

GetOptions(\%args, 'field=s', 'update','replace' ,'help', 'verbose'); 


if ($args{'help'} || !($args{'update'}||$args{'replace'}) ){ 
help(); 
exit; 
} 

# Load customer assets 
my $assetobj = RTx::AssetTracker::Assets->new($RT::SystemUser); 
$assetobj->FromSQL('Type = "Customers" AND Status != "retired"'); 

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

$cf->Load( $args{'field'} ); 
unless ( $cf->id ) { 
die "Couldn't find that custom field\n"; 
} 

if ( $args{'replace'} ) { 
my $values = $cf->Values; 
my %map; 

# Clear all values 
while ( my $value = $values->Next ) { 
$value->Delete(); 

} 
} 

if ( $args{'update'} || $args{'replace'} ) { 
my $values = $cf->Values; 
my @current; 

$assetobj->First; 

while ( my $value = $values->Next ) { 

push @current, $value->Name; 
} 

while (my $asset = $assetobj->Next) { 
unless ( grep { $asset eq $_ } @current ) { 
print STDERR "Adding " . $asset . "\n" if ($args{'verbose'}); 
my ( $ret, $val ) = $cf->AddValue( Name => $asset->Name."|".$asset->Id ); 
} 
} 

} 

print STDERR "Done\n" if ($args{'verbose'}); 



sub help { 

print <<EOF 

$0 is a simple RT tool to add values to a custom field. 
It takes several arguments: 


--field The id or name of the custom field you'd like to work with 
--update Add values to this field, but do not prune unused files 
--replace Make the custom field contain only the values listed 


This script expects a list of potential custom field values, 
one per line to be fed to STDIN. 

Example: 

$0 --field "My CF Name" --update < list_of_values 

EOF 

} 



Scrip "updateCustomerID" 
Custom Condition 
my $trans = $self->TransactionObj->Type; 

# If it's not a Create or CustomField update, then exit 
if ( $trans ne 'Create' && $trans ne 'CustomField' ) { return 0; } 

Custom Action Cleanup code 
my @tmp = split(/\|/, $self->TransactionObj->OldValue); 
my $old_value = $tmp[1]; 

@tmp = split(/\|/, $self->TicketObj->FirstCustomFieldValue('Customer')); 
my $new_value = $tmp[1]; 

my $asset = RTx::AssetTracker::Asset->new($self->CurrentUser); 
my ($id,$msg) = $asset->Load($new_value); 
if (! $id) { 
$RT::Logger->crit("Could not load asset $new_value: $msg"); 
return 0; 
} 
($id,$msg) = $self->TicketObj->AddLink(Type => 'RefersTo', Target => 
$asset->URI); 
if (! $id) { 
$RT::Logger->crit("Could not AddLink: $msg"); 
return 0; 
} 

# If the value has changed, then delete old link 
if ($old_value ne $new_value && $old_value) { 
my ($id,$msg) = $asset->Load($old_value); 
($id,$msg) = $self->TicketObj->DeleteLink(Type => 'RefersTo', Target => 
$asset->URI); 
if (! $id) { 
$RT::Logger->crit("Could not DeleteLink: $msg"); 
return 0; 
} 
} 

1; 


1; 



-- 
Med venlig hilsen / Best regards 

Tommy Abrahamsson 

----- Original Message ----- 
From: "Matt Gilstrap" <[EMAIL PROTECTED]> 
To: [email protected] 
Sent: 7. januar 2008 21:15:28 (GMT+0100) Europe/Berlin 
Subject: [rt-users] Asset Tracker list in ticket custom field 





I was wondering if anyone has figured out a way to create a custom field in a 
ticket that lists all of the assets in Asset Tracker. We would like to be able 
to track changes made to each server in the network and find it cumbersome to 
have to go to the asset first to create the ticket or to find the asset number 
and manually add “at://rw3.com/asset/11” to the refers to field. Any ideas, 
workarounds, complaints, ridicule are much appreciated. 



Cheers, 

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

SAVE THOUSANDS OF DOLLARS ON RT SUPPORT:

If you sign up for a new RT support contract before December 31, we'll take
up to 20 percent off the price. This sale won't last long, so get in touch 
today. 
    Email us at [EMAIL PROTECTED] or call us at +1 617 812 0745.


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

Reply via email to