set_active_variant()
Activates an existing variant of a document via std.SetActiveVariant. Unlike
insert_variant() with set_active=True, this method
operates on a variant tree that already exists.
The server job also needs the currently active variant (dwPrevActVarID), which the caller
usually does not know. It is resolved in the cheapest available way:
-
from
previously_active_idwhen given — no extra server roundtrip, -
from the variant tree of a model instance that was loaded with
variants=True, -
otherwise with one
variants()call.
Activating the variant that is already active does nothing and performs no job.
1. Signature
-
Sync
-
Async
ecm.dms.set_active_variant(
variant: int | ECMDocumentModel | ECMModelDocumentVariant,
object_type_id: int | None = None,
*,
previously_active_id: int | ECMDocumentModel | ECMModelDocumentVariant | None = None,
) -> None
await ecm.dms.set_active_variant(
variant: int | ECMDocumentModel | ECMModelDocumentVariant,
object_type_id: int | None = None,
*,
previously_active_id: int | ECMDocumentModel | ECMModelDocumentVariant | None = None,
) -> None
2. Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
|
|
— |
The variant to activate: a numeric ID, a model instance, or a node from |
|
|
|
The numeric object type ID. If |
|
|
|
The currently active variant, in the same three shapes. Skips reading the variant tree, and with it the checks below. |
4. Exceptions
| Exception | Condition |
|---|---|
|
A passed model instance has no |
|
The document has no variants at all (not a W-document), or no variant in the tree is active. |
|
The server returns no object for that ID. |
std.SetActiveVariant overwrites two IDs without validating them. A wrong or unrelated
dwPrevActVarID therefore leaves the tree with two active variants or with none. The checks
above cover exactly those cases — with previously_active_id the caller takes that
responsibility instead.
5. Examples
5.1. Re-activate the original document
-
Sync
-
Async
doc = ecm.dms.get(InvoiceDocument, 12345)
ecm.dms.set_active_variant(doc)
doc = await ecm.dms.get(InvoiceDocument, 12345)
await ecm.dms.set_active_variant(doc)
5.2. Activate a variant from the loaded tree
-
Sync
-
Async
doc = ecm.dms.get(InvoiceDocument, 12345, variants=True)
target = next(v for root in doc.system.variants for v in root.walk() if v.doc_ver == "2.0.0")
ecm.dms.set_active_variant(target, doc.system.type_id)
doc = await ecm.dms.get(InvoiceDocument, 12345, variants=True)
target = next(v for root in doc.system.variants for v in root.walk() if v.doc_ver == "2.0.0")
await ecm.dms.set_active_variant(target, doc.system.type_id)
5.3. Switch without an extra lookup
When the previously active variant is known — from an earlier query, for instance — the
variants() roundtrip is not needed:
-
Sync
-
Async
active = ecm.dms.active_variant(12345)
new_id, _ = ecm.dms.insert_variant(InvoiceDocument(Name="Correction"), 12345)
ecm.dms.set_active_variant(new_id, 327685, previously_active_id=active)
active = await ecm.dms.active_variant(12345)
new_id, _ = await ecm.dms.insert_variant(InvoiceDocument(Name="Correction"), 12345)
await ecm.dms.set_active_variant(new_id, 327685, previously_active_id=active)
6. See also
-
variants() — read the variant tree
-
active_variant() — read the active variant
-
insert_variant() — create a new variant, optionally active right away