From da2f9e7500b08f4a8f942617a2d10bef922b16ed Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Tue, 19 Nov 2019 14:56:05 +0000 Subject: [PATCH] Bug 9156: itemcallnumber not pulling more than 2 subfields When the itemcallnumber system preference is defined, the item add form pulls data from the specified tag and subfield(s) to pre-populate the call number field. This update makes it possible to build the prepopulated callnumber from more than just the first two subfields. To test, apply the patch and update the itemcallnumber system preference so that it includes more than two subfields. For instance, "092abef" - Edit a bibliographic record and populate the specified subfields. e.g. subfield a -> "One", b-> "Two", e-> "Three", f-> "Four". - Save the record and go to the add/edit items screen. - The call number field should contain a string which contains each of the subfields you populated, concatenated with spaces: "One Two Three Four." - Test with other numbers of subfields. - Test with an empty itemcallnumber preference. Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- cataloguing/additem.pl | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 2c371def28..38fb34bc3c 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -154,17 +154,23 @@ sub generate_subfield_form { my $pref_itemcallnumber = C4::Context->preference('itemcallnumber'); if (!$value && $subfieldlib->{kohafield} eq 'items.itemcallnumber' && $pref_itemcallnumber) { - my $CNtag = substr($pref_itemcallnumber, 0, 3); - my $CNsubfield = substr($pref_itemcallnumber, 3, 1); - my $CNsubfield2 = substr($pref_itemcallnumber, 4, 1); + my $CNtag = substr( $pref_itemcallnumber, 0, 3 ); # 3-digit tag number + my $CNsubfields = substr( $pref_itemcallnumber, 3 ); # Any and all subfields + my @subfields = ( $CNsubfields =~ m/./g ); # Split into single-character elements my $temp2 = $temp->field($CNtag); + if ($temp2) { - $value = join ' ', $temp2->subfield($CNsubfield) || q{}, $temp2->subfield($CNsubfield2) || q{}; + my @selectedsubfields; + foreach my $subfieldcode( @subfields ){ + push @selectedsubfields, $temp2->subfield( $subfieldcode ); + } + $value = join( ' ', @selectedsubfields ); + #remove any trailing space incase one subfield is used $value =~ s/^\s+|\s+$//g; } } - + if ($frameworkcode eq 'FA' && $subfieldlib->{kohafield} eq 'items.barcode' && !$value){ my $input = new CGI; $value = $input->param('barcode'); -- 2.39.5