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 [2018/09/05 18:06] – [Managing citations and bibliographies] Add brackets for getNote() zuphilipdev:client_coding:javascript_api [2018/09/09 05:08] – [API Methods] zuphilip
Line 200: Line 200:
 var itemids = collection.getChildItems(true); var itemids = collection.getChildItems(true);
 </code> </code>
 +
 +=== Create a New Collection in a function ===
 +
 +<code javascript>
 +async function createCollection(name) {
 +    var currentCollection = ZoteroPane.getSelectedCollection();
 +    var collection = new Zotero.Collection();
 +    collection.name = name;
 +    collection.parentID = currentCollection.id;
 +    var collectionID = await collection.saveTx();
 +    return collectionID;
 +}
 +</code>
 +
 +This function creates a new collection with a given name and makes
 +it a subcollection of the currently selected one. Since the saving
 +will result in a Promise object, we add the ''await'' before the
 +function call and make sure that this is within an ''async'' function.
  
 ==== Zotero Search Basics ==== ==== Zotero Search Basics ====
dev/client_coding/javascript_api.txt · Last modified: 2022/07/02 18:22 by dstillman