Saving a document (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.


You can save documents via scripts in BizzStream in two different methods.

persistent.saveDocument: When a document is saved in a script, a REST call is executed in the background. The script only continues when the REST call returned a response.

persistent.saveDocumentLazy: The document will be saved after the script has been executed. BizzStream doesn't wait for a response because the script doesn't use the response. With this method you can save documents in scripts lazily so that the script execution time will be reduced.


You can use the following method in your script

persistent.saveDocument(ddName, document);
Parameter Type Required Description
ddName String Yes Name of the document definition
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.

Examples

You can use the following method to save a document in BizzStream 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"
    }
);

If you provide an ID for which no document exists, BizzStream throws an error.

You can use the following method to insert a new document. The reason for this is that the document does not contain an the id_ field:

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

Case: How can you update the "code" property of the document to 6789?

//Step 1: Assign the value to a variable
var newCode = 6789

//Step 2: You always have access to the serverDocument. Assign the variable to the object property "code"
serverDocument.code = newCode

//Step 3: Persist the document
persistent.saveDocument('project', serverDocument)

results matching ""

    No results matching ""