<html><head><style type='text/css'>body { font-family: 'Times New Roman'; font-size: 12pt; color: #000000}</style></head><body>Hi Matt<br><br>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.<br><br>There's a Scrip which creates a link to the Asset automatically when creating a new ticket.<br><br>It works great, but may not be as pretty :)<br><br>I've attached everything for you here. Hope it works out for you.<br><br>Btw. we're using RT 3.6.5.<br><br><span style="font-weight: bold;">cronjob</span><br>#!/usr/bin/perl<br><br>use warnings;<br>use strict;<br><br>use lib qw(/opt/rt3/local/lib /opt/rt3/lib);<br>use Getopt::Long;<br><br>use RT;<br>use RTx::AssetTracker;<br>use RTx::AssetTracker::Assets;<br>use RTx::AssetTracker::Asset;<br>use RTx::AssetTracker::Types;<br>use RTx::AssetTracker::Type;<br>RT::LoadConfig();<br>RT::Init();<br><br>my %args;<br><br>GetOptions(\%args, 'field=s', 'update','replace' ,'help', 'verbose');<br><br><br> if ($args{'help'} || !($args{'update'}||$args{'replace'}) ){<br> help();<br> exit;<br> }<br><br># Load customer assets<br>my $assetobj = RTx::AssetTracker::Assets->new($RT::SystemUser);<br>$assetobj->FromSQL('Type = "Customers" AND Status != "retired"');<br><br>my $cf = RT::CustomField->new(RT->SystemUser);<br><br>$cf->Load( $args{'field'} );<br>unless ( $cf->id ) {<br> die "Couldn't find that custom field\n";<br>}<br><br>if ( $args{'replace'} ) {<br> my $values = $cf->Values;<br> my %map;<br><br> # Clear all values<br> while ( my $value = $values->Next ) {<br> $value->Delete();<br><br> }<br>}<br><br>if ( $args{'update'} || $args{'replace'} ) {<br> my $values = $cf->Values;<br> my @current;<br><br> $assetobj->First;<br><br> while ( my $value = $values->Next ) {<br><br> push @current, $value->Name;<br> }<br><br> while (my $asset = $assetobj->Next) {<br> unless ( grep { $asset eq $_ } @current ) {<br> print STDERR "Adding " . $asset . "\n" if ($args{'verbose'});<br> my ( $ret, $val ) = $cf->AddValue( Name => $asset->Name."|".$asset->Id );<br> }<br> }<br><br>}<br><br>print STDERR "Done\n" if ($args{'verbose'});<br><br><br><br>sub help {<br><br>print <<EOF<br><br>$0 is a simple RT tool to add values to a custom field. <br>It takes several arguments:<br><br><br> --field The id or name of the custom field you'd like to work with<br> --update Add values to this field, but do not prune unused files<br> --replace Make the custom field contain only the values listed<br><br><br>This script expects a list of potential custom field values,<br>one per line to be fed to STDIN.<br><br>Example:<br><br>$0 --field "My CF Name" --update < list_of_values<br><br>EOF<br><br>}<br><br><br><br><span style="font-weight: bold;">Scrip "updateCustomerID"</span><br><span style="font-style: italic;">Custom Condition</span><br>my $trans = $self->TransactionObj->Type;<br><br># If it's not a Create or CustomField update, then exit<br>if ( $trans ne 'Create' && $trans ne 'CustomField' ) { return 0; }<br><br><span style="font-style: italic;">Custom Action Cleanup code</span><br>my @tmp = split(/\|/, $self->TransactionObj->OldValue);<br>my $old_value = $tmp[1];<br><br>@tmp = split(/\|/, $self->TicketObj->FirstCustomFieldValue('Customer'));<br>my $new_value = $tmp[1];<br><br>my $asset = RTx::AssetTracker::Asset->new($self->CurrentUser);<br>my ($id,$msg) = $asset->Load($new_value);<br>if (! $id) {<br>$RT::Logger->crit("Could not load asset $new_value: $msg");<br>return 0;<br>}<br>($id,$msg) = $self->TicketObj->AddLink(Type => 'RefersTo', Target =><br>$asset->URI);<br>if (! $id) {<br>$RT::Logger->crit("Could not AddLink: $msg");<br>return 0;<br>}<br><br># If the value has changed, then delete old link<br>if ($old_value ne $new_value && $old_value) {<br>my ($id,$msg) = $asset->Load($old_value);<br>($id,$msg) = $self->TicketObj->DeleteLink(Type => 'RefersTo', Target =><br>$asset->URI);<br>if (! $id) {<br>$RT::Logger->crit("Could not DeleteLink: $msg");<br>return 0;<br>}<br>}<br><br>1; <br><br><br>1;<br><br><br><br>--<br>Med venlig hilsen / Best regards<br><br>Tommy Abrahamsson<br><br>----- Original Message -----<br>From: "Matt Gilstrap" <mgilstrap@rw3.com><br>To: rt-users@lists.bestpractical.com<br>Sent: 7. januar 2008 21:15:28 (GMT+0100) Europe/Berlin<br>Subject: [rt-users] Asset Tracker list in ticket custom field<br><br>
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div lang="EN-US">
<div class="Section1">
<p class="MsoNormal">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.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Cheers,</p>
<p class="MsoNormal">Matt</p>
</div>
</div>
</body></html>