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 (vote)
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-08-09 16:20 UTC by Eric Phetteplace
Modified: 2023-08-09 16:20 UTC (History)
1 user (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


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.