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/03/30 00:34] – [Batch Editing] Add creator editing example dstillman | dev:client_coding:javascript_api [2020/10/17 20:58] – [Batch Editing] dstillman | ||
---|---|---|---|
Line 11: | Line 11: | ||
- In the Tools → Developer menu, select Run JavaScript. Opening the Error Console, which appears in the same menu, will also be helpful. | - In the Tools → Developer menu, select Run JavaScript. Opening the Error Console, which appears in the same menu, will also be helpful. | ||
- | - In the window that opens, enter JavaScript in the Code textbox and click Run or press Cmd-R/ | + | - In the window that opens, enter some JavaScript in the Code textbox and click Run or press Cmd-R/ |
When running **asynchronous** code containing '' | When running **asynchronous** code containing '' | ||
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 ==== |