Skip to content

Save documents (persistent.saveDocument)

You can use persistent.saveDocument to save a document in the database. You can use this method to create a new document or to update an already existing document.

There is also persistent.saveDocumentLazy to save a document after the script is executed.

These two functions can not directly be used with V1 documents. Use 'persistent.saveDocumentV1' or 'persistent.saveDocumentLazyV1' to save documents for V1.

Syntax

persistent.saveDocument(ddName, document)

persistent.saveDocumentLazy(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.
overwritePrevious Boolean No (Only for lazy) A boolean that indicates whether a previous version of the same document in the queue should be overwritten.
async Boolean No (Only for lazy) A boolean that indicates whether the document should be saved asynchronously after completing the script. By setting this parameter to true, you ensure that BizzStream places the document in a queue after completing the script. BizzStream will continue with the next rules in the action, while the documents in the queue are saved in the background.

Return value

An object containing the inserted or updated document.

Example

The following example shows how to update a document with ID 2FwMgqxxPv6i4j8rc:

persistent.saveDocument("project",
  { 
    "_id":"2FwMgqxxPv6i4j8rc",
    "_documentDefinitionId":"iaK8uBLxDqmTJzYdL",
    "_environmentId":"a83rh4aX5nzBsGL3S",
    "accessGroups":[],
    "code":"12345",
    "name":"Constructing Highway",
    "companyId":"a6PbuPzkoRp3Czqcv",
    "externalId":"bdr:200¡adm:05¡prj:6"
  }
);

Example with lazy

The following example shows how to update a document with ID 2FwMgqxxPv6i4j8rc after script is executed:

persistent.saveDocumentLazy("project",
  { 
    "_id":"2FwMgqxxPv6i4j8rc",
    "_documentDefinitionId":"iaK8uBLxDqmTJzYdL",
    "_environmentId":"a83rh4aX5nzBsGL3S",
    "accessGroups":[],
    "code":"12345",
    "name":"Constructing Highway",
    "companyId":"a6PbuPzkoRp3Czqcv",
    "externalId":"bdr:200¡adm:05¡prj:6"
  },
  false,
  false
);