Skip to content

updateDocument

Updated pdexter 2022-10-22

Function to update a document.

(client & server-side function)

Syntax

ft3.updateDocument(doc-id, change, user-id, function(err, doc) {

  ...

});

Part Description
doc-id documentId of the document to update
change JSON of the change to perform
user-id documentId of the user
err if an error occurred, contains the error message
doc if successful, the final document

WARNING

(Applies to Formbird prior to v3.1.x)

Using updateDocument within a PostSave ruleset on the same document can result in a runaway process where the document keeps saving over and over ad infinitum.

Preferably, move any such changes to PreSaveServer where the ntf.document object can still be modified normally, without needing to call updateDocument.

If it is necessary to still use it in PostSave, then use the PostSaveLoopPrevention method to update the document.

Formbird v3.1.x and later has built in protection from looping PostSave self updates.

-- pd 2020-06-03

Example

    var change = {
        'saDateMark' : new Date()
    };

    ft3.updateDocument(ntf.document.documentId, change, ntf.user.documentId, 
    function(err, doc) {
        if (err) {
            ntf.logger.error('Error in updateDocument: ' + err);
        }
        else {
            ntf.logger.info('Document updated successfully.');
        }
        callback();
    });