updateData()
Overview
public numeric function updateData(
required string objectName
, required struct data
, string id
, any filter
, struct filterParams
, array extraFilters
, array savedFilters
, boolean forceUpdateAll = false
, boolean updateManyToManyRecords = false
, boolean isDraft = false
, boolean useVersioning = auto
, numeric versionNumber = 0
, boolean forceVersionCreation = false
, boolean setDateModified = true
, boolean clearCaches = Defaults to whether query caching is enabled or not for this object
, boolean calculateChangedData = false
, struct changedData = If this is a non-empty struct updateData will use it and not calculate the changed data
, numeric timeout
)
Updates records in the database with a new set of data. Returns the number of records affected by the operation.
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
| objectName | string | Yes | Name of the object whose records you want to update |
| data | struct | Yes | Structure of data containing new values. Keys should map to properties on the object. |
| id | string | No | ID of a single record to update |
| filter | any | No | Filter for which records are updated, see :ref:`preside-objects-filtering-data` in :doc:`/devguides/presideobjects` |
| filterParams | struct | No | Filter params for plain SQL filter, see :ref:`preside-objects-filtering-data` in :doc:`/devguides/presideobjects` |
| extraFilters | array | No | An array of extra sets of filters. Each array should contain a structure with :code:`filter` and optional `code:`filterParams` keys. |
| savedFilters | array | No | |
| forceUpdateAll | boolean | No (default=false) | If no ID and no filters are supplied, this must be set to **true** in order for the update to process |
| updateManyToManyRecords | boolean | No (default=false) | Whether or not to update multiple relationship records for properties that have a many-to-many relationship |
| isDraft | boolean | No (default=false) | Whether or not the record update is a draft change. Draft changes are only saved against the version table until published. |
| useVersioning | boolean | No (default=auto) | Whether or not to use the versioning system with the update. If the object is setup to use versioning (default), this will default to true. |
| versionNumber | numeric | No (default=0) | If using versioning, specify a version number to save against (if none specified, one will be created automatically) |
| forceVersionCreation | boolean | No (default=false) | |
| setDateModified | boolean | No (default=true) | If true (default), updateData will automatically set the datelastmodified date on your record to the current date/time |
| clearCaches | boolean | No (default=Defaults to whether query caching is enabled or not for this object) | Whether or not to clear caches related to the object whose record you are updating |
| calculateChangedData | boolean | No (default=false) | |
| changedData | struct | No (default=If this is a non-empty struct updateData will use it and not calculate the changed data) | |
| timeout | numeric | No | Timeout, in seconds, of the main update DB query |
Examples
// update a single record
updated = presideObjectService.updateData(
objectName = "event"
, id = eventId
, data = { enddate = "2015-01-31" }
);
// update multiple records
updated = presideObjectService.updateData(
objectName = "event"
, data = { cancelled = true }
, filter = { category = rc.category }
);
// update all records
updated = presideObjectService.updateData(
objectName = "event"
, data = { cancelled = true }
, forceUpdateAll = true
);