Replace Single Character in Names through JavaScript Batch Editing
I'm looking for assistance replacing a single character in the creator/author names field. I've looked at some examples using other fields but cannot make it work with the name field, especially single field mode names (e.g. "XYZ Institute"). Maybe because it's an array?
What I have is one collection with corporate names that imported with a "$" instead of a comma. I want to keep the one-field fieldMode while replacing the $ with a comma.
For example, "U.S. EPA$ Office of Research" becomes "U.S. EPA, Office of Research" without changing the fieldMode into firstName "Office of Research" and lastName "U.S. EPA."
Does that make sense?
In any case, Tools -> Run JavaScript, run this:
for (let item of ZoteroPane.getSelectedItems()) {
item.setCreators(item.getCreators().map(c => {
if (c.fieldMode === 1) {
c.lastName = c.lastName.replace('$ ', ', ');
}
return c;
}));
await item.saveTx();
}
https://s3.amazonaws.com/zotero.org/images/forums/u2397286/a9ea1y06q90d6tvbv4dd.jpg
I suspect I'm missing something very basic?