Bug 34508 - MARC modification templates have poor results when working with multiple of a field
Summary: MARC modification templates have poor results when working with multiple of a...
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Cataloging (show other bugs)
Version: 22.11
Hardware: All All
: P5 - low enhancement
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-08-09 16:20 UTC by Eric Phetteplace
Modified: 2026-03-09 13:11 UTC (History)
4 users (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: ---
Comma delimited list of Sponsors:
Crowdfunding goal: 0
Crowdfunding committed: 0
Crowdfunding contact:
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
minimal example record (376 bytes, text/plain)
2023-08-09 16:20 UTC, Eric Phetteplace
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Phetteplace 2023-08-09 16:20:05 UTC
Created attachment 154334 [details]
minimal example record

MARC modification templates "copy and replace" actions struggle to modify records in an expected manner when there are multiple of the field being modified. There are at least two unexpected results:

- a "copy and replace" on the "1st" of two fields results in the first field's modified subfield being copied to the second
- using an "if" condition with either the "1st" or "all" fields also causes the first field's modified subfield to overwrite the second's subfield, even if the second does not meet the if condition

I've attached a minimal MARC record with two 856 fields. The goal of a modification template should be to modify only the first "example.com" ‡u subfield while leaving the second untouched. However, both of these modification templates result in the second 856‡u being a copy of the first.

1) Copy and replace 1st field 856$u to 856$u using RegEx s/^http?s://example\.com/https://proxy.cca.edu/?url=https://example.com/

2) Copy and replace field 856$u to 856$u using RegEx s/^http?s://example\.com/https://proxy.cca.edu/?url=https://example.com/ if 856$u matches RegEx m/https?://example\.com.*/

Original record:
245 _ _ ‡aTest record for MARC modification
856 4 0 ‡uhttps://example.com‡yProxy link
856 4 0 ‡uhttps://cca.edu‡yRetain link

Expected outcome:
245 _ _ ‡aTest record for MARC modification
856 4 0 ‡uhttps://proxy.cca.edu/?url=https://example.com‡yProxy link
856 4 0 ‡uhttps://cca.edu‡yRetain link

Actual outcome:
245 _ _ ‡aTest record for MARC modification
856 4 0 ‡uhttps://proxy.cca.edu/?url=https://example.com‡yProxy link
856 4 0 ‡uhttps://proxy.cca.edu/?url=https://example.com‡yRetain link

Note that the second field's ‡y subfield is untouched. For template #1, I expect the second field not to be modified because it specifies only the "1st" MARC field. For template #2, I expect the second field not to be modified because it does not match the if condition. In BOTH templates, the regex substitution should not affect the second field, because it does not match the pattern.

There was a thread on the Koha listserv between myself and Caroline Cyr La Rose from August 4th to August 9th, 2023 that may provide helpful details.
Comment 1 Anneli Österman 2026-02-27 10:45:22 UTC
I can confirm that this is still an issue.

It also works like this:

I'm using Copy and replace 1st field 264c to field 264c with regex to strip the trailing dot.

264 1 _a Helsinki:
      _b Sangatsu Manga,
      _c [2017].
264 3 _a Liettua:
      _b ScandBook UAB
264 4 _c ©2017.

It ends up like this

264 1 _a Helsinki :
      _b Sangatsu Manga,
      _c [2017]
264 3 _a Liettua :
      _b ScandBook UAB
      _c [2017]
264 4 _c [2017]

So it adds subfield c to the second 264 with the first ones data and changes third ones field c with the data from first field.

If I try to modify All fields the result is like this:

264  1 _aHelsinki :
       _bSangatsu Manga,
       _c[2017]
264  3 _aLiettua :
       _bScandBook UAB
       _c©2017
264  4 _c

It "moves" the third field's subfield c to the second field and leaves the third one "empty".

These make using MARC modification templates/batch MARC modification almost impossible when the field is repeated.