Customizable Extra/General Fields
I searched on this topic, and while I found relevant discussions I did not find an exact answer. Does Zotero have any way to add in a GUI field(s) in the "extra" or other general fields? As an example, JabRef allows users to customize the "general" fields (link: https://docs.jabref.org/setup/generalfields). My use case would be for setting up fields such as "sample size" or "research methodology."
My searches lead me to believe this isn't possible with Zotero, but I wanted to confirm. I suspect I could manually do this by adding "samplesize:xxx" etc. to the "extra" field, but a more clean approach would be appreciated.
Thanks all.
My searches lead me to believe this isn't possible with Zotero, but I wanted to confirm. I suspect I could manually do this by adding "samplesize:xxx" etc. to the "extra" field, but a more clean approach would be appreciated.
Thanks all.
Sample size: 123
Design: Longitudinal
Custom user fields are planned for the medium-term, but aren't currently available.
You could write a script to add these values to all of the Extra fields in your library.
https://www.zotero.org/support/dev/client_coding/javascript_api#batch_editing
I think this should work. Fill in the values for groupID and newValues below, then run it using the JavaScript runner in Tools -> Developer -> Run JavaScript. The groupID is the group number you see in the URL for the group on zotero.org.
var fieldName = "extra";
var groupID = "<ENTER GROUP NUMBER HERE>";
var newValues = "<ENTER KEYS YOU WANT HERE, SEPARATE LINES WITH '\n'>";
var fieldID = Zotero.ItemFields.getID(fieldName);
let libraryID = Zotero.Groups.getLibraryIDFromGroupID(groupID);
var ids = await Zotero.Items.getAll(libraryID, true, false, true);
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 mappedFieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(item.itemTypeID, fieldName);
let oldValue = item.getField(mappedFieldID ? mappedFieldID : fieldID);
let newValue = oldValue + "\n" + newValues;
item.setField(mappedFieldID ? mappedFieldID : fieldID, newValue);
await item.save();
}
});
return ids.length + " item(s) updated";
I started reviewing the tutorial for writing a plugin, but this seems a bit easier. I just gave it a go and ran into an error: oldValue not defined.
I see why it is being raised. If I define an oldValue I can get the script to work beautifully on the documents that have the 'extra' field set to whatever I define as 'oldValue'.
I first tried to remove the s.addCondition line, but that threw an error "Error: '22' is not a valid field for type 14."
Next, I tried to change the s.addCondition to s.addCondition(fieldName, 'is', 'any'); but that did not find any records.
Is there a way to apply this to all documents, regardless of what content is in their extra field already? I looked at the search basics on the link you recommended, and it looked like I could search without specifying conditions so I'm not sure why the error is being thrown.
I appreciate your quick responses and help.
At the moment I cannot find a way to add information in the "extra" space in a way that it exports properly as multiple separately labelled columns in a CSV file which is causing a lot of extra manual labour.
For multilingual records I really need a way to duplicate many fields and the "extra" "catch all"
doesn't work for CSV export :(