Batch "switch to" two fields or one field on creators

I've ended up with a chunk of items with 'one field' creators, other than re-importing them all with a fix, is there a way to batch edit items to switch creators to one or two fields?
I checked zutilo, but no luck, I assume I'd need to use javascript?

Any help much appreciated
  • Hi

    I'm struggling with JavaScript (no coding experience), but it definitely seems possible. You want to set the creator.fieldMode to equal 0.

    See "Example: Creator Name Changes" here https://www.zotero.org/support/dev/client_coding/javascript_api#adding_items_and_modifying_data

    In a parallel thread, I've been seeking some JavaScript help, as it would take me some time fiddling to generate a full solution for you... https://forums.zotero.org/discussion/109393/more-change-item-javascript-examples-for-non-developers-please/p1

    M
  • Thanks @mileshastie that was super useful and gave me enough to play and get something.
    I think the translators are designed to do a better job of name splitting, and this solution will result in errors (but at the moment I have a big load of all errors...so this makes it a smaller set I can manually fix).

    Oddly creator.lastName is where my names are, not creator.name (which I think is a field used when fieldMode == 1). Code below or gist https://gist.github.com/sjgknight/9a1ba937220621abcda38f401dbe7c80

    var newFieldMode = 0; // 0: two-field, 1: one-field (with empty first name)

    const zoteroPane = Zotero.getActiveZoteroPane();
    const selected = zoteroPane.getSelectedItems();

    for (const item of selected) {
    let creators = item.getCreators();
    let newCreators = []; // Initialize newCreators array
    for (let creator of creators) {
    if(creator.fieldMode == 1){
    let oldname = creator.lastName;
    creator.fieldMode = newFieldMode;
    creator.firstName = oldname.split(' ').slice(0, -1).join(' ');
    creator.lastName = oldname.split(' ').slice(-1).join(' ');
    }
    newCreators.push(creator);
    }

    item.setCreators(newCreators);
    await item.save();
    }

    return selected.length + " item(s) updated";
Sign In or Register to comment.