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

πŸ“¦ version 2.3, in ubuntu noble

πŸ’– RT::Ex...t::CSV(3pm) πŸ’–

okay bestie, so this page is User Contributed Perl Documentation for RT-Extension-Assets-Import-CSV and it is genuinely one of the most useful little tools in the RT universe. it's giving "import all ur assets from a CSV and let RT handle the rest" energy and honestly? obsessed. let's get into it πŸ¦‹


✨ NAME ✨

RT-Extension-Assets-Import-CSV β€” RT Assets Import from CSV. that's it, that's the whole vibe. ur CSV goes in, ur assets come out πŸ’…


🌸 PREREQUISITES 🌸

so here's the tea, bestie: this version of RT::Extension::Assets::Import::CSV requires RT 4.4, because that version of RT has Assets built in. built-in assets, no extra plugins, we love to see it 🫢

but if you're running RT 4.2 with the Assets extension, you need to go find an older version of this extension instead β€” specifically, version 1.4. don't try to make the new one work on the old setup, it's not gonna slay, it's gonna flop 😭


πŸŽ€ INSTALLATION πŸŽ€

okay so the whole install arc, step by step:

  • perl Makefile.PL
  • make
  • make install β€” may need root permissions πŸ‘‘
  • Edit your /opt/rt5/etc/RT_SiteConfig.pm. add this line:
Plugin('RT::Extension::Assets::Import::CSV');

(and see "CONFIGURATION" below for the remainder of the required configuration β€” don't skip that part, it's not optional πŸ’€)

  • Restart your webserver. yes you have to. yes it's annoying. it's mandatory.
  • Run bin/rt-assets-import-csv

See bin/rt-assets-import-csv --help for more information ✨


πŸ’œ CONFIGURATION πŸ’œ

here's where the main character energy really kicks in. the following configuration would be used to import a three-column CSV of assets, where the column titled serviceTag is unique:

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

like. look at that mapping. it's so clean. it's so organized. 🧚


🌈 Constant values 🌈

so if you want to set an RT column or custom field to a static value for all imported assets, you 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',
);

every imported asset will now be added to the Hardware catalog in RT. this feature is particularly useful for setting the asset catalog, but it may also be useful when importing assets from CSV sources you don't control (and don't want to modify each time). no cap, that last bit is the real lifesaver β€” sometimes u just get a cursed CSV from someone else and u can't touch it πŸ™ˆ


πŸ¦‹ Computed values πŸ¦‹

you may also compute values during import, by passing a subroutine reference as the value in the %AssetsImportFieldMapping. this subroutine will be called with a hash reference of the parsed CSV row:

Set( $AssetsImportUniqueCF, 'Service Tag' );
Set( %AssetsImportFieldMapping,
    'Name'           => 'description',
    'CF.Service Tag' => 'serviceTag',
    'CF.Location'    => 'building',
    'CF.Weight'      => sub { $_[0]->{"Weight (kg)"} || "(unknown)" },
);

look at that little sub. a fallback. a safety net. we love a graceful default πŸ₯Ή

⚠️ heads up bestie: using computed columns may cause false-positive "unused column" warnings; these can be ignored. don't panic, it's not real. it's giving drama queen warning, not actual problem πŸ’…

⭐ Numeric identifiers ⭐

if you are already using a numeric identifier to uniquely track your assets, and you wish RT to take over handling of that identifier, 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',
);
🚨 okay this one matters: this requires that, after the import, RT becomes the generator of all asset ids. otherwise, asset id conflicts may occur. read that again. we do not want id conflicts. that's the bad ending, fr fr 😭

πŸ‘‘ AUTHOR πŸ‘‘

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


πŸ’€ BUGS πŸ’€

all bugs should be reported via email to

L<bug-RT-Extension-Assets-Import-CSV@rt.cpan.org|mailto:bug-RT-Extension-Assets-Import-CSV@rt.cpan.org>

or via the web at

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

if u found a bug, tell them! that's how it gets fixed, bestie 🫢


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's documented by perl v5.36.0, dated 2023-08-27, and honestly? go import those assets. ur RT is gonna look so good. slay πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from