Mailing List Archive

Assets with 'dynamic' titles
Hey,

I'm wanting to use Assets to track, well, our assets. But I'll be
tracking hard drives and a few other components as well which don't
have a specific name . Is it possible to have the subject dynamically
generated using a combination of Custom Fields and even potentially
relationships?

Ideally I'd have something like:

HDD $manufacturer $serial_number

Where $manufacturer $serial_number both come from Custom Fields.

Cheers,
Andrew

--
Andrew Ruthven, Wellington, New Zealand
andrew@etc.gen.nz             | linux.conf.au 2017, Hobart, AU
  New Zealand's only Cloud:   |   The Future of Open Source
https://catalyst.net.nz/cloud |     http://linux.conf.au
Re: Assets with 'dynamic' titles [ In reply to ]
Probably?

If you copy Asset.pm from its home to $RT4/local/lib/RT/Asset_Local.pm, you can modify the Create subroutine (and then probably delete all the routines that you don't override). I'd aim for someplace around lines 222-231 (of the original file):

222 my $catalog = RT::Catalog->new( $self->CurrentUser );
223 $catalog->Load($args{'Catalog'});
224
225 $args{'Catalog'} = $catalog->id;
226
227 return (0, $self->loc("Permission Denied"))
228 unless $catalog->CurrentUserHasRight('CreateAsset');
229
230 return (0, $self->loc('Invalid Name (names may not be all digits)'))
231 unless $self->ValidateName( $args{'Name'} );

If you create a Catalog for "Things that don't have a specific name", you can search for its $catalog->id, then generate the name for assets that are in that catalog. Something like:

227 return (0, $self->loc("Permission Denied"))
228 unless $catalog->CurrentUserHasRight('CreateAsset');
229
230 # This code snippet is not tested. Please hack at it in a test environment before relying on it.
231 # let's make some assumptions
232 # - "Things that don't have a specific name" is Catalog #2
233 # - Type of Thing ('HDD', for example) is Custom Field #12
234 # - Manufacturer is Custom Field #23
235 # - Serial Number is Custom Field #48
236 if ($catalog->id==2) {
237 $args{'Name'} = $args{'CustomField-12'} . ' ' . $args{'CustomField-23'} . ' '. $args{'CustomField-48'};
238 }
239
240 return (0, $self->loc('Invalid Name (names may not be all digits)'))
241 unless $self->ValidateName( $args{'Name'} );

(Offhand, I don't know for certain that $catalog->id will be numeric, and not a string. You might need to use a string comparison in the if statement.)

Good luck,
Kyle
--
Kyle Dippery
Engineering Computing Services
219 RMB
859-257-1346

________________________________________
From: rt-users <rt-users-bounces@lists.bestpractical.com> on behalf of Andrew Ruthven <andrew@etc.gen.nz>
Sent: Tuesday, February 21, 2017 3:03 PM
To: rt-users
Subject: [rt-users] Assets with 'dynamic' titles

Hey,

I'm wanting to use Assets to track, well, our assets. But I'll be
tracking hard drives and a few other components as well which don't
have a specific name . Is it possible to have the subject dynamically
generated using a combination of Custom Fields and even potentially
relationships?

Ideally I'd have something like:

HDD $manufacturer $serial_number

Where $manufacturer $serial_number both come from Custom Fields.

Cheers,
Andrew

--
Andrew Ruthven, Wellington, New Zealand
andrew@etc.gen.nz | linux.conf.au 2017, Hobart, AU
New Zealand's only Cloud: | The Future of Open Source
https://catalyst.net.nz/cloud | http://linux.conf.au