Bug 28231

Summary: MARC modification template "1st" vs "Every" bug?
Product: Koha Reporter: Caroline Cyr La Rose <caroline.cyr-la-rose>
Component: ToolsAssignee: Bugs List <koha-bugs>
Status: NEW --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low    
Version: Main   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: MARC authority record with two 151$x

Description Caroline Cyr La Rose 2021-04-26 20:07:54 UTC
Created attachment 120184 [details]
MARC authority record with two 151$x

Hi all,

I think this is a bug, if someone could confirm, I would appreciate it!

In MARC modification templates, we have the option of choosing to modify the first or every field specified. But when trying to delete only the first occurrence of a subfield, it deletes every subfield anyway.

To test:
1) Create an authority record with two 151$x, one containing [BLANK] and the other containing real information (I've attached my authority record if you want to simply import it)
2) Go to Tools > MARC modification templates
3) Create a new template
4) Add the following action
Delete 1st field(s) 151 x
if field 151 x matches [BLANK]
5) Go to Tools > Batch record modification
6) Fill in the form
Record type: Authorities
Enter a list of record numbers: enter the authid of your authority record
Modify record using the following template: Template created previously
7) Click Continue
8) Click "Show MARC"

Both 151$x are deleted, rather than just the first one
Comment 1 Caroline Cyr La Rose 2021-04-26 21:32:27 UTC
I did some more experimenting

Delete 1st 151 x
if 151 x matches [BLANK]

    Expected: only the first $x will be deleted
    Result: both $x are deleted

Delete Every 151 x
if 151 x matches [BLANK]

    Expected: both $x will be deleted
    Result: both $x are deleted

Move 1st 151 x to 151 g RegEx \[BLANK\] / gggg /
if 151 x matches [BLANK]

    Expected: one $x remaining and one $g with gggg
    Result: no $x, one $g with gggg

Move Every 151 x to 151 g RegEx \[BLANK\] / gggg /
if 151 x matches [BLANK]

    Expected: one $g with gggg (? not sure about this? Should the $xRecensement still be there because it doesn't match the RegEx?)
    Result: one $g with gggg

Copy 1st 151 x to 151 g RegEx \[BLANK\] / gggg /
if 151 x matches [BLANK]

    Expected: two $x remaining, one new $g with gggg
    Result: two $x remaining, one new $g with gggg

Copy Every 151 x to 151 g RegEx \[BLANK\] / gggg /
if 151 x matches [BLANK]

    Expected: two $x remaining, one new $g with gggg (I think? again, I'm not sure if the RegEx has any effect on which $x is copied)
    Result: two $x remaining, one new $g with gggg

Copy and replace 1st 151 x to 151 g RegEx \[BLANK\] / gggg /
if 151 x matches [BLANK]

    Expected: two $x and one $g with gggg
    Result: two $x and one $g with gggg

Copy and replace Every 151 x to 151 g RegEx \[BLANK\] / gggg /
if 151 x matches [BLANK]

    Expected: two $x and one $g with gggg
    Result: two $x and one $g with gggg