Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
dev:client_coding:javascript_api [2020/04/16 16:02] – [Running Ad Hoc JavaScript in Zotero] dstillmandev:client_coding:javascript_api [2020/10/17 20:58] – [Batch Editing] dstillman
Line 20: Line 20:
 </code> </code>
  
-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 mode with+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 mode with
  
 <code javascript> <code javascript>
Line 422: Line 422:
 return ids.length + " item(s) updated";</code> return ids.length + " item(s) updated";</code>
  
-==== Example: Delete Tags By Name ====+==== Example: Convert manual tag in selected library to automatic tag ====
  
-<html><p id="zotero-5-update-warningstyle="colorred; font-weight: bold">This example has not been updated for Zotero 5 and should not currently be used.</p></html>+Replace "Fooin the first line with the tag to change:
  
-<code javascript>var tags ["foo", "bar", "baz"]+<code javascript>var tag = "Foo"; 
-var ids []+var new Zotero.Search()
-var allTags Zotero.Tags.search(); +s.libraryID ZoteroPane.getSelectedLibraryID(); 
-tags = tags.map(tag => tag.toLowerCase()); +s.addCondition('tag', 'is', tag); 
-for (var id in allTags{ +var ids = await s.search(); 
-    if (tags.indexOf(allTags[id].name.toLowerCase()) != -1) { +if (!ids.length{ 
-      ids.push(id); +    return "No items found";
-    }+
 } }
-Zotero.Tags.erase(ids); +for (let id of ids) { 
-</code>+    let item = Zotero.Items.get(id); 
 +    item.addTag(tag, 1); 
 +    await item.saveTx(); 
 +
 +return ids.length + " tag(s) updated";</code>
  
 ==== Example: Delete Tags By Part of Name ==== ==== Example: Delete Tags By Part of Name ====
dev/client_coding/javascript_api.txt · Last modified: 2022/07/02 18:22 by dstillman