Get a document (persistent.getDocumentV1)
You can use persistent.getDocumentV1 to find a specific document based on a particular document definition. Unlike persistent.getDocument, this method throws an error when the document ID is different from a valid string.
Syntax
persistent.getDocumentV1(ddName, documentId);
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 example below illustrates document retrieval from the database using a document ID. In contrast to persistent.getDocument, the call is enclosed in a try...catch construct to handle the case where serverDocument._id is undefined, which would otherwise result in an error being thrown.
try {
const doc = persistent.getDocumentV1(serverDocument._documentDefinitionName, serverDocument._id)
console.log(doc);
console.log('Retrieved order:', doc._environmentId);
} catch(error) {
console.log(error);
}