Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
dev:client_coding:javascript_api [2020/04/16 16:02] – [Running Ad Hoc JavaScript in Zotero] dstillman | dev:client_coding:javascript_api [2020/10/17 20:58] – [Batch Editing] dstillman | ||
---|---|---|---|
Line 20: | Line 20: | ||
</ | </ | ||
- | In **synchronous** mode, the value of the final line will appear in the right-hand pane. The same result as above could be achieved in synchonous | + | In **synchronous** mode, the value of the final line will appear in the right-hand pane. The same result as above could be achieved in synchronous |
<code javascript> | <code javascript> | ||
Line 422: | Line 422: | ||
return ids.length + " item(s) updated";</ | return ids.length + " item(s) updated";</ | ||
- | ==== Example: | + | ==== Example: |
- | < | + | Replace |
- | <code javascript> | + | <code javascript> |
- | var ids = []; | + | var s = new Zotero.Search(); |
- | var allTags | + | s.libraryID |
- | tags = tags.map(tag => tag.toLowerCase()); | + | s.addCondition('tag', ' |
- | for (var id in allTags) { | + | var ids = await s.search(); |
- | if (tags.indexOf(allTags[id].name.toLowerCase()) | + | if (!ids.length) { |
- | | + | |
- | | + | |
} | } | ||
- | Zotero.Tags.erase(ids); | + | for (let id of ids) { |
- | </ | + | let item = Zotero.Items.get(id); |
+ | | ||
+ | await item.saveTx(); | ||
+ | } | ||
+ | return ids.length + " tag(s) updated"; | ||
==== Example: Delete Tags By Part of Name ==== | ==== Example: Delete Tags By Part of Name ==== |