Add Document Settings
Summary
The add method stores or updates a value in Document Settings. If the key already exists, it is overwritten. Values are scoped to the current document.
Purpose
- Store document-specific notes or annotations
- Save document-level review status, tags, or metadata
- Persist extension state for a specific document
Syntax
SigmaSDK.WRITER.storage.document.add({ key: "key", value: "value" })Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
key | String | Yes | The storage key |
value | String | Yes | The value to store (must be a string) |
Note: Values must be strings. Use
JSON.stringify() to store objects, and JSON.parse() to retrieve them.Basic Example
SigmaSDK.WRITER.storage.document.add({ key: "reviewStatus", value: "approved" })
.then(function() {
console.log("Status saved to document");
});Storing Structured Data
const docMeta = { reviewer: "Alice", approvedOn: "2024-01-15", notes: "Looks good" };
SigmaSDK.WRITER.storage.document.add({
key: "reviewData",
value: JSON.stringify(docMeta)
});Complete Example
<!DOCTYPE html>
<html>
<head>
<title>Document Notes Widget</title>
<script src="https://static.zohocdn.com/sigma/client/sdk/v3/sigma-sdk.min.js"></script>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
textarea { width: 100%; height: 100px; }
button { padding: 10px 20px; margin: 5px; cursor: pointer; }
#status { color: green; margin-top: 10px; }
</style>
</head>
<body>
<h1>Document Notes</h1>
<textarea id="notes" placeholder="Enter document notes..."></textarea>
<br>
<button onclick="saveNotes()">Save Notes</button>
<button onclick="loadNotes()">Load Notes</button>
<p id="status"></p>
<script>
SigmaSDK.WRITER.init().then(loadNotes);
async function saveNotes() {
const notes = document.getElementById("notes").value;
await SigmaSDK.WRITER.storage.document.add({ key: "notes", value: notes });
document.getElementById("status").textContent = "Notes saved!";
}
async function loadNotes() {
const notes = await SigmaSDK.WRITER.storage.document.fetch("notes");
if (notes) document.getElementById("notes").value = notes;
}
</script>
</body>
</html>