[rt-users] Solved: Trying to use a CSV file as a custom field values source: "Can't use string (...) as an ARRAY ref while "strict refs" in use."
oscoffrobvetaxem
oscoffrobvetaxem at tin-fan.com
Sat Sep 27 18:33:02 EDT 2014
Wow, turns out I just needed a good nap...
Lots wrong with my first try, not sure how I thought that was going to work!
Anyways, for everybody else looking to figure this out, the functioning code
follows:
> package RT::CustomFieldValues::LaborItems;
>
> use strict;
> use warnings;
>
> use base qw(RT::CustomFieldValues::External);
> use Text::CSV;
>
> sub SourceDescription {
> return 'Labor items from the POS.';
> }
>
> sub ExternalValues {
> my @csvdata = []; # Create an empty array for CSV data.
> my $file =
'/var/rt4/lib/RT/CustomFieldValues/item_listing_LABOR.csv';
>
> my $csv = Text::CSV -> new({ sep_char => ',' });
> open ( my $cvsfh, '<', $file ) or die "Could not open $file: $!";
>
> while( my $row = $csv -> getline( $cvsfh ) ) {
> push @csvdata, $row;
> }
> shift @csvdata;
# Removes the first line, just has column names.
>
> my @customvalues;
> for my $csvline ( @csvdata ){
> my $itemname = $csvline->[5];
> my $price = $csvline->[7];
> my $cvname = join "", $itemname, " - ", $price;
# Stick the price on the end of the name.
> my $cvhash->{ 'name' } = $cvname ;
> push( @customvalues, $cvhash );
> }
> return \@customvalues;
> }
>
> #dump &ExternalValues;
>
> RT::Base->_ImportOverlays();
>
> 1;
RT is now successfully populating the custom field values!
--
View this message in context: http://requesttracker.8502.n7.nabble.com/Trying-to-use-a-CSV-file-as-a-custom-field-values-source-Can-t-use-string-as-an-ARRAY-ref-while-stri-tp58645p58646.html
Sent from the Request Tracker - User mailing list archive at Nabble.com.
More information about the rt-users
mailing list