Fetch Document Settings
Summary
The fetch method retrieves a stored value from Document Settings by its key. Returns null if the key does not exist. Values are scoped to the current document.
Purpose
- Retrieve document-specific configuration or notes
- Load document-level extension state on startup
- Check if document-specific data exists
Syntax
SigmaSDK.WRITER.storage.document.fetch(key)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
key | String | Yes | The key to fetch from document storage |
Response
Returns a Promise that resolves with the stored string value, or null if the key is not found.
Basic Example
SigmaSDK.WRITER.storage.document.fetch("notes")
.then(function(value) {
if (value) {
document.getElementById("notes").value = value;
}
});With Async/Await
async function loadDocumentData() {
await SigmaSDK.WRITER.init();
const notes = await SigmaSDK.WRITER.storage.document.fetch("notes");
const status = await SigmaSDK.WRITER.storage.document.fetch("reviewStatus");
document.getElementById("notes").value = notes || "";
document.getElementById("status").value = status || "pending";
}Fetch Multiple Keys with Promise.all
const [notes, status, tags] = await Promise.all([
SigmaSDK.WRITER.storage.document.fetch("notes"),
SigmaSDK.WRITER.storage.document.fetch("reviewStatus"),
SigmaSDK.WRITER.storage.document.fetch("tags")
]);
console.log({ notes, status, tags });Error Handling
SigmaSDK.WRITER.storage.document.fetch("my_key")
.then(function(value) {
return value || "default";
})
.catch(function(error) {
console.error("Fetch failed:", error);
});