[rt-users] Asset Tracker list in ticket custom field

Tommy Abrahamsson tab at secu.dk
Mon Jan 7 15:08:25 EST 2008

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. 


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; 

my %args; 

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

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

# 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 ) { 


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


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. 


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



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 => 
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 => 
if (! $id) { 
$RT::Logger->crit("Could not DeleteLink: $msg"); 
return 0; 



Med venlig hilsen / Best regards 

Tommy Abrahamsson 

----- Original Message ----- 
From: "Matt Gilstrap" <mgilstrap at rw3.com> 
To: rt-users at lists.bestpractical.com 
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. 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20080107/437b0dda/attachment.htm>

More information about the rt-users mailing list