this has been planned for a long time and is on the medium-term agenda, if we're luck it might make it into Zotero 4.2, more likely the major version after.
For now, one could do that using the Javscript API as mentioned here: https://www.zotero.org/support/dev/client_coding/javascript_api
Just install the ExecuteJS plugin in Firefox and then open a new tab and open Zotero there. Now, use ExecuteJS to execute your custom JS which modifies all the required items at once.
used the code below, didn't work. any guidance will be appreciated
__________________________________________
var fieldName = "itemType";
var oldValue = "Book";
var newValue = "Journal Article";
var fieldID = Zotero.ItemFields.getID(fieldName);
var s = new Zotero.Search;
s.addCondition(fieldName, 'is', oldValue);
var ids = s.search();
if (ids) {
for each(var id in ids) {
var item = Zotero.Items.get(id);
var mappedFieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(item.itemTypeID, fieldName);
item.setField(mappedFieldID ? mappedFieldID : fieldID, newValue);
item.save();
}
alert(ids.length + " items updated");
}
else {
alert("No items found");
}
ah sorry for not spotting that. Those should be "book" and "journalArticle" respectively. See http://aurimasv.github.io/z2csl/typeMap.xml for a full list.
edit: though it's also possible that this basic method just doesn't work for item types; I don't know that part of the code well enough.
yes those variables were changed, but still got:
Error: Invalid field 'itemType" for base field in ItemFields.getFieldIDFromTypeAndBase()
var fieldName = "itemType";
var oldValue = "book";
var newValue = "journalArticle";
var fieldID = Zotero.ItemFields.getID(fieldName);
var s = new Zotero.Search;
s.addCondition(fieldName, 'is', oldValue);
var ids = s.search();
if (ids) {
for (var i in ids) {
var item = Zotero.Items.get(ids[i]);
var mappedFieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(item.itemTypeID, fieldName);
item.setField(mappedFieldID ? mappedFieldID : fieldID, newValue);
item.save();
}
alert(ids.length + " items updated");
}
else {
alert("No items found");
}
var oldValue = "book"; var newValue = "journalArticle";
var s = new Zotero.Search; s.addCondition('itemType', 'is', oldValue); var ids = s.search(); if (ids) { for (var i in ids) { var item = Zotero.Items.get(ids[i]); item.setField('itemType', newValue); item.save(); } alert(ids.length + " items updated"); } else { alert("No items found"); }
If that doesn't work, then I don't think that itemType can be changed with a simple bit of code.
For batch editing of item types through Zotero's JavaScript API, see this discussion.
You could also use the Zutilo add-on, which now provides a "Paste item type" function.
The Zutilo functions for batch editing of item metadata are: "Copy item fields", "Paste into empty item fields", "Paste non-empty item fields", "Paste all item fields", and "Paste item type". They are explained in Zutilo's Command reference. Use cases are discussed in the Usage notes.
You should keep in mind that changing the type of Zotero items can give rise to data loss for some fields. Currently, only valid fields are preserved. See this discussion.
"this has been planned for a long time and is on the medium-term agenda". It's 2022. Any news of "Search and Replace"? Please. Implement. It. How to replace hundreds of items' attributes? KR
thanks
Just install the ExecuteJS plugin in Firefox and then open a new tab and open Zotero there. Now, use ExecuteJS to execute your custom JS which modifies all the required items at once.
__________________________________________
var fieldName = "itemType";
var oldValue = "Book";
var newValue = "Journal Article";
var fieldID = Zotero.ItemFields.getID(fieldName);
var s = new Zotero.Search;
s.addCondition(fieldName, 'is', oldValue);
var ids = s.search();
if (ids) {
for each(var id in ids) {
var item = Zotero.Items.get(id);
var mappedFieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(item.itemTypeID, fieldName);
item.setField(mappedFieldID ? mappedFieldID : fieldID, newValue);
item.save();
}
alert(ids.length + " items updated");
}
else {
alert("No items found");
}
You could try
for (var i in ids) {
var item = Zotero.Items.get(ids[i]);
I think that should work.
I changed the lines as instructed, got rid of the "for each" error
getting this one instead:
Error: Invalid field 'itemType" for base field in ItemFields.getFieldIDFromTypeAndBase()
I wanted to change multiple entries that have "Item Type" field "Books" to "Journal Article"
Thanks again!
Peter
edit: though it's also possible that this basic method just doesn't work for item types; I don't know that part of the code well enough.
Error: Invalid field 'itemType" for base field in ItemFields.getFieldIDFromTypeAndBase()
var fieldName = "itemType";
var oldValue = "book";
var newValue = "journalArticle";
var fieldID = Zotero.ItemFields.getID(fieldName);
var s = new Zotero.Search;
s.addCondition(fieldName, 'is', oldValue);
var ids = s.search();
if (ids) {
for (var i in ids) {
var item = Zotero.Items.get(ids[i]);
var mappedFieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(item.itemTypeID, fieldName);
item.setField(mappedFieldID ? mappedFieldID : fieldID, newValue);
item.save();
}
alert(ids.length + " items updated");
}
else {
alert("No items found");
}
var oldValue = "book";
var newValue = "journalArticle";
var s = new Zotero.Search;
s.addCondition('itemType', 'is', oldValue);
var ids = s.search();
if (ids) {
for (var i in ids) {
var item = Zotero.Items.get(ids[i]);
item.setField('itemType', newValue);
item.save();
}
alert(ids.length + " items updated");
}
else {
alert("No items found");
}
If that doesn't work, then I don't think that itemType can be changed with a simple bit of code.
the code gave me this message: "itemType" is not a valid itemData field.
thanks to you and adamsmith for trying!
I guess I will be spending the next hour changing entries.
Peter
with following script :(
var fieldName = "itemType";
var oldValue = "journalArticle";
var newValue = "report";
var fieldID = Zotero.ItemFields.getID(fieldName);
var items = Zotero.getActiveZoteroPane().getSelectedItems();
await Zotero.DB.executeTransaction(async function () {
for (let item of items ) {
let mappedFieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(item.itemTypeID, fieldName);
item.setField(mappedFieldID ? mappedFieldID : fieldID, newValue);
await item.save();
}
});
return items.length + " item(s) updated";
You could also use the Zutilo add-on, which now provides a "Paste item type" function.
The Zutilo functions for batch editing of item metadata are: "Copy item fields", "Paste into empty item fields", "Paste non-empty item fields", "Paste all item fields", and "Paste item type". They are explained in Zutilo's Command reference. Use cases are discussed in the Usage notes.
var fieldName = "report";
const zoteroPane = Zotero.getActiveZoteroPane();
const selected = zoteroPane.getSelectedItems();
for (const item of selected) {
item.setType(Zotero.ItemTypes.getID(fieldName));
await item.saveTx();
}
return selected.length + " item(s) updated";