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
)

Updates records in the database with a new set of data. Returns the number of records affected by the operation.

Arguments

NameTypeRequiredDescription
objectNamestringYesName of the object whose records you want to update
datastructYesStructure of data containing new values. Keys should map to properties on the object.
idstringNoID of a single record to update
filteranyNoFilter for which records are updated, see :ref:`preside-objects-filtering-data` in :doc:`/devguides/presideobjects`
filterParamsstructNoFilter params for plain SQL filter, see :ref:`preside-objects-filtering-data` in :doc:`/devguides/presideobjects`
extraFiltersarrayNoAn array of extra sets of filters. Each array should contain a structure with :code:`filter` and optional `code:`filterParams` keys.
savedFiltersarrayNo
forceUpdateAllbooleanNo (default=false)If no ID and no filters are supplied, this must be set to **true** in order for the update to process
updateManyToManyRecordsbooleanNo (default=false)Whether or not to update multiple relationship records for properties that have a many-to-many relationship
isDraftbooleanNo (default=false)Whether or not the record update is a draft change. Draft changes are only saved against the version table until published.
useVersioningbooleanNo (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.
versionNumbernumericNo (default=0)If using versioning, specify a version number to save against (if none specified, one will be created automatically)
forceVersionCreationbooleanNo (default=false)
setDateModifiedbooleanNo (default=true)If true (default), updateData will automatically set the datelastmodified date on your record to the current date/time
clearCachesbooleanNo (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

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
);