Last active
June 25, 2024 14:49
-
-
Save zuphilip/1c9d0b91c796e3a5ccbd19f1d3355ad4 to your computer and use it in GitHub Desktop.
Zotero Script for moving custom field notes (e.g. imported from Citavi) to some field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Move value from #CostumField notes with fixed label | |
// to a different field. Set these two fields according to your needs. | |
var label = "Standortsignatur"; | |
var field = "callNumber"; | |
// List of all possible fields: | |
// https://api.zotero.org/itemFields?pprint=1 | |
var check = true; | |
var test = false; | |
var overwrite = false; | |
var trashNotes = false; | |
var items = Zotero.getActiveZoteroPane().getSelectedItems(); | |
for (let item of items) { | |
if (item.itemType == "note") { | |
break; | |
} | |
noteIDs = item.getNotes(); | |
for (let nid of noteIDs) { | |
let note = Zotero.Items.get(nid); | |
var noteHTML = note.getNote(); | |
var noteText = Zotero.Utilities.unescapeHTML(noteHTML); | |
let skip = true; | |
for (let tag of note.getTags()) { | |
if (tag.tag == "#CustomField") { | |
Zotero.log(noteText); | |
skip = false; | |
break; | |
} | |
} | |
if (skip && check) { | |
continue; | |
} | |
Zotero.log(noteText); | |
var parts = noteText.split(":"); | |
if (parts.length >= 2 && parts[0] == label) { | |
parts.shift(); | |
value = parts.join(":").trim(); | |
var content = item.getField(field); | |
if (!content || overwrite) { | |
Zotero.log("WRITE '" + value + "' in field " + field); | |
if (test) { | |
continue; | |
} | |
item.setField(field, value); | |
item.saveTx(); | |
if (trashNotes) { | |
Zotero.Items.trashTx(nid); | |
} | |
} | |
} | |
} | |
} | |
items; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a preview of its use:
