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 [2019/10/20 06:32] – [Managing citations and bibliographies] zuphilip | dev:client_coding:javascript_api [2020/03/30 00:34] – [Batch Editing] Add creator editing example dstillman | ||
---|---|---|---|
Line 249: | Line 249: | ||
Here we use Zotero' | Here we use Zotero' | ||
- | specified in Zotero' | + | specified in Zotero' |
+ | bibliography from all currently selected items. | ||
- | First we start with a list of as in the previous entry. | + | <code javascript> |
- | + | var qc = Zotero.QuickCopy; | |
- | <code javascript> | + | |
var format = Zotero.Prefs.get(" | var format = Zotero.Prefs.get(" | ||
if (format.split(" | if (format.split(" | ||
- | return | + | alert("No bibliography style is choosen in the settings for QuickCopy." |
} | } | ||
- | var biblio = qc.getContentFromItems([item], format); | + | var biblio = qc.getContentFromItems(items, format); |
var biblio_html_format = biblio.html; | var biblio_html_format = biblio.html; | ||
var biblio_txt = biblio.text; | var biblio_txt = biblio.text; | ||
</ | </ | ||
+ | |||
+ | If you instead want to have the citation string then simply replace the 7th | ||
+ | line with '' | ||
+ | |||
=== Get a list of available styles === | === Get a list of available styles === | ||
Line 275: | Line 279: | ||
</ | </ | ||
- | TODO: get citations. | + | TODO: change the style. |
especially RTF | especially RTF | ||
Line 349: | Line 353: | ||
===== Batch Editing ===== | ===== Batch Editing ===== | ||
- | The JavaScript API can provide | + | The JavaScript API provides |
Before proceeding, back up your [[: | Before proceeding, back up your [[: | ||
Line 382: | Line 386: | ||
https:// | https:// | ||
+ | |||
+ | ==== Example: Creator Name Changes ==== | ||
+ | |||
+ | Edit the first four lines as necessary: | ||
+ | |||
+ | <code javascript> | ||
+ | var newFirstName = " | ||
+ | var newLastName = " | ||
+ | var newFieldMode = 0; // 0: two-field, 1: one-field (with empty first name) | ||
+ | |||
+ | var s = new Zotero.Search(); | ||
+ | s.libraryID = Zotero.Libraries.userLibraryID; | ||
+ | s.addCondition(' | ||
+ | var ids = await s.search(); | ||
+ | if (!ids.length) { | ||
+ | return "No items found"; | ||
+ | } | ||
+ | await Zotero.DB.executeTransaction(async function () { | ||
+ | for (let id of ids) { | ||
+ | let item = await Zotero.Items.getAsync(id); | ||
+ | let creators = item.getCreators(); | ||
+ | let newCreators = []; | ||
+ | for (let creator of creators) { | ||
+ | if (`${creator.firstName} ${creator.lastName}`.trim() == oldName) { | ||
+ | creator.firstName = newFirstName; | ||
+ | creator.lastName = newLastName; | ||
+ | creator.fieldMode = newFieldMode; | ||
+ | } | ||
+ | newCreators.push(creator); | ||
+ | } | ||
+ | item.setCreators(newCreators); | ||
+ | await item.save(); | ||
+ | } | ||
+ | }); | ||
+ | return ids.length + " item(s) updated";</ | ||
==== Example: Delete Tags By Name ==== | ==== Example: Delete Tags By Name ==== |