Retrieving a Document (persistent.getDocument)
You can use persistent.getDocument
to retrieve a specific document from the environments database using its unique identifier (id).
Syntax
persistent.getDocument(ddName, documentId);
Parameters
The getDocument function takes the following parameters:
Parameter | Type | Required | Description |
---|---|---|---|
ddName | String or null |
Yes | If the value is null , BizzStream will use the name of the document from which the script was started. |
documentId | String | Yes | The unique identifier (ID) of the document to retrieve. |
Return value
Returns an object representing the requested document if found. The structure of this document object is similar to the objects used when saving or finding documents. Returns an error if no document with the specified ID is found.
{
"_id": "String id",
"status": "ready",
"accessGroups": [
{
"_id": ["OBJECT"],
"memberUserIds": ["Array"],
"memberGroupIds": ["Array"],
"memberRelatedAccessGroupIds": []
}
],
"_documentDefinitionId": "String id",
"_environmentId": "String id",
"_createdByUserId": "String id",
"_lastModifiedOn": "Date",
"_createdOn": "Date",
"_lastModifiedByUserId": "String id",
"_hash": "String"
}
Example
The following example shows how to retrieve a document from the database by ID:
const doc = persistent.getDocument(serverDocument._documentDefinitionName, serverDocument._id)
if (doc) {
console.log(doc);
console.log('Retrieved order:', doc._environmentId);
} else {
console.log('Order not found.');
}