RT::Ex...t::CSV(3pm)

πŸ“¦
version 2.3 Β· 2 versions
, in debian bookworm

πŸ’– NAME πŸ’–

RT-Extension-Assets-Import-CSV β€” that's the whole personality: RT Assets Import from CSV. You got a spreadsheet, you got assets, this extension makes them meet. πŸ’…

Oh and real quick, the page you're reading right now is filed under the manual name RT::Ex...t::CSV(3pm) β€” yes, it's squished and truncated like that, that's just how the header renders it, we move. ✨


🌸 PREREQUISITES 🌸

  • This version of RT::Extension::Assets::Import::CSV requires RT 4.4, periodt β€” because that version of RT has Assets built right in. No extra extension, they just live there. Iconic.
  • If you're running RT 4.2 with the Assets extension, bestie, you need an older version of this extension β€” specifically version 1.4. Go get that one, it's the one for you. 🫢

πŸŽ€ INSTALLATION πŸŽ€

  1. Do the classic three-step. In order. No skipping:
perl Makefile.PL
make
make install
make install may need root permissions. Yeah. Sudo o'clock. πŸ™ˆ
  1. Edit your /opt/rt5/etc/RT_SiteConfig.pm β€” drop this line in:
Plugin('RT::Extension::Assets::Import::CSV');

Then go look at CONFIGURATION below, because that's where the rest of the required configuration lives. Don't skip it, it's not optional, fr fr.

  1. Restart your webserver. πŸ’«
  2. Run bin/rt-assets-import-csv.

Want more deets on that script? See bin/rt-assets-import-csv --help.


πŸ¦‹ CONFIGURATION πŸ¦‹

So here's the scenario: you've got a three-column CSV of assets, and the column titled serviceTag is unique. That config would look exactly like this:

Set( $AssetsImportUniqueCF, 'Service Tag' );
Set( %AssetsImportFieldMapping,
    'Name'           => 'description',
    'CF.Service Tag' => 'serviceTag',
    'CF.Location'    => 'building',
    'CF.Serial #'    => 'serialNo',
);

πŸ“ Constant values πŸ“

Wanna set an RT column or a custom field to a static value for every single imported asset? Precede the "CSV field name" (that's the right hand side of the mapping) with a slash, like so:

Set( $AssetsImportUniqueCF, 'Service Tag' );
Set( %AssetsImportFieldMapping,
    'Name'           => 'description',
    'Catalog'        => \'Hardware',
    'CF.Service Tag' => 'serviceTag',
    'CF.Location'    => 'building',
    'CF.Serial #'    => 'serialNo',
);

Now every imported asset gets added to the Hardware catalog in RT. Obsessed, honestly. This feature is particularly useful for setting the asset catalog, but it also hits different when you're importing assets from CSV sources you don't control (and you do not want to hand-edit that file every single time). πŸ™…β€β™€οΈ

🧚 Computed values 🧚

You can also compute values during import by passing a subroutine reference as the value in the %AssetsImportFieldMapping. That subroutine gets called with a hash reference of the parsed CSV row. Main character behavior:

Set( $AssetsImportUniqueCF, 'Service Tag' );
Set( %AssetsImportFieldMapping,
    'Name'           => 'description',
    'CF.Service Tag' => 'serviceTag',
    'CF.Location'    => 'building',
    'CF.Weight'      => sub { $_[0]->{"Weight (kg)"} || "(unknown)" },
);
Heads up though: using computed columns may cause false-positive "unused column" warnings. These can be ignored. Not a bug, just noise, ignore it and thrive. 😌

πŸ’œ Numeric identifiers πŸ’œ

Already using a numeric identifier to uniquely track your assets, and you want RT to take over handling of that identifier? Say less. You can choose to leave $AssetsImportUniqueCF unset, and assign to "id" in the %AssetsImportFieldMapping:

Set( %AssetsImportFieldMapping,
    'id'             => 'serviceTag',
    'Name'           => 'description',
    'CF.Service Tag' => 'serviceTag',
    'CF.Serial #'    => 'serialNo',
);
⚠️ This requires that, after the import, RT becomes the generator of all asset ids. Otherwise? Asset id conflicts may occur. And not the cute kind of conflict. So be sure before you commit, bestie.

πŸ‘‘ AUTHOR πŸ‘‘

Best Practical Solutions, LLC <modules@bestpractical.com>


πŸ’€ BUGS πŸ’€

All bugs should be reported via email to

bug-RT-Extension-Assets-Import-CSV@rt.cpan.org

or via the web at

http://rt.cpan.org/Public/Dist/Display.html?Name=RT-Extension-Assets-Import-CSV

(Those two are the same links the original page shows as L<bug-RT-Extension-Assets-Import-CSV@rt.cpan.org|mailto:bug-RT-Extension-Assets-Import-CSV@rt.cpan.org> and L<rt.cpan.org|http://rt.cpan.org/Public/Dist/Display.html?Name=RT-Extension-Assets-Import-CSV>, in case you're a purist. 🫑)


This extension is Copyright (C) 2014-2021 Best Practical Solutions, LLC.

This is free software, licensed under:

The GNU General Public License, Version 2, June 1991

And that's the whole page, babe. πŸŽ€ This one shipped as perl v5.34.0, dated 2022-06-24, and it goes by the manual name RT::Ex...t::CSV(3pm). Go import something cute. Byeee! πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from