Skip to content

updateDocument

Updated pdexter 2024-01-12

Function to update a document.

(client & server-side function)

Syntax

Client

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

  ...

});

Server

ft3.updateDocument(doc-id, change, user-id, [ options,] 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
options (server only | optional) options to provide to the updateDocument function
err if an error occurred, contains the error message
doc if successful, the final document

Options

The following options can be set for updateDocument (server only):

Option Description
triggerPreSaveServer Boolean
If false, bypasses any preSaveServer ruleset processing on the save.
Default: true

This is useful for when there is a need to synchronise other documents, but not necessarily run all of its save processing.
Very useful to avoid cascading document changes, where doc A changes doc B, doc B changes doc A, etc etc ad infinitum
triggerPostSaveServer Boolean
If false, bypasses any postSaveServer ruleset processing on the save.
Default: true

~~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();
    });

Example with options

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

var options = {
    triggerPreSaveServer : false,
    triggerPostSaveServer : false
};

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