Batch Editing
Hi!
I would like to batch edit hundreds of items in my library. As far as I saw elsewhere on the forum, there is no automated way to do this, but I found the following javascript solution:
https://www.zotero.org/support/dev/client_coding/javascript_api#examplebatch_editing
While the script seems fairly easy to use, it is unfortunately not exactly what I need and I do not have the skills to write such a script myself.
I would like to add in the language field "Arabic" (which changes name capitalisation rules). These items could be identified by a search in the name field, since all the Arabic entries have special characters. A typical name field would look like this:
"Ḥaqāʾiq Thawrat Sibtimbir al-Yamanīya: Iʿdādān wa-Tanfīdhān (Facts of the September Revolution: Preparation and Implementation)"
Could anyone help me with a script that could, for example, add "Arabic" to the language field of all entries that contain the letter ā?
Thanks so much in advance!
I would like to batch edit hundreds of items in my library. As far as I saw elsewhere on the forum, there is no automated way to do this, but I found the following javascript solution:
https://www.zotero.org/support/dev/client_coding/javascript_api#examplebatch_editing
While the script seems fairly easy to use, it is unfortunately not exactly what I need and I do not have the skills to write such a script myself.
I would like to add in the language field "Arabic" (which changes name capitalisation rules). These items could be identified by a search in the name field, since all the Arabic entries have special characters. A typical name field would look like this:
"Ḥaqāʾiq Thawrat Sibtimbir al-Yamanīya: Iʿdādān wa-Tanfīdhān (Facts of the September Revolution: Preparation and Implementation)"
Could anyone help me with a script that could, for example, add "Arabic" to the language field of all entries that contain the letter ā?
Thanks so much in advance!
As for your actual query, if you can create one in Advanced Search, then you can transfer it pretty easily into that javascript example. For your very simplified version, you could do
s.addCondition('title', 'contains', 'ā');
and then set fieldName to 'language' and newValue to 'ar-SA' at the top.Happy New Year! Thanks so much for the prompt and helpful advice. I very much appreciate it!
I tried running the search with the condition you specified above:
var fieldName = “language”; var oldValue = ""; var newValue = “ar-YE“; var fieldID = Zotero.ItemFields.getID(fieldName); var s = new Zotero.Search; s.addCondition('title', 'contains', 'ā'); 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"); }
When I ran the script I got the error message "SyntaxError: illegal character" which I suppose has to do with character encoding.
I would be glad to generate a more complex search string, but do not understand how to transfer it from the advanced search to the script. If I created the string with the search, it would probably solve the encoding issue as well, wouldn't it?
Thank you!
var fieldName = “language”; var oldValue = ""; var newValue = “ar-YE“;