Emit events (persistent.saveDocumentV1)
You can use persistent.saveDocumentV1
to save a document in the database. You can use this method to create a new document or to update an already existing document. Unlike persistent.saveDocument, this method returns a string rather than an object.
Syntax
persistent.saveDocumentV1(ddName, document)
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
ddName | String or null |
Yes | The name of the document definition. If the value is null , BizzStream will use the name of the document from which the script was started. |
Document | Object | Yes | The JSON object that contains the document you wish to save. In case the document does not contain an _id-field or in case no document with the entered ID exists, a new document will be created. In the other case an existing document will be updated. |
Return value
An string containing the inserted or updated document. To get the document, use the JSON.parse
method:
let result = persistent.saveDocumentV1("order", document);
result = JSON.parse(result);
Example
The following example shows how to update a document with ID 2FwMgqxxPv6i4j8rc:
persistent.saveDocumentV1("project",
{ "_id":"2FwMgqxxPv6i4j8rc",
"_documentDefinitionId":"iaK8uBLxDqmTJzYdL",
"_environmentId":"a83rh4aX5nzBsGL3S",
"accessGroups":[],
"code":"12345",
"name":"Constructing Highway",
"companyId":"a6PbuPzkoRp3Czqcv",
"externalId":"bdr:200¡adm:05¡prj:6"
}
);