updateDocument
Updated pdexter 2025-05-20
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 |
| triggerPreSaveOffline | Boolean If false, bypasses any preSaveOffline ruleset processing on the save. Default: true (works from preSaveOffline) |
Recent versions of the Formbird application (Formbird v3.1.x and later) have built in protection from looping PostSave on updates to the same document from its PostSave ruleset. Ie., acts as if triggerPostSaveServer is false.
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,
triggerPreSaveOffline : 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();
});