You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.

set()

Usage

 set(entity, key1, value1, key2, value2, ..., keyN, valueN)
 set(entity, json)
 set(entity, map)

Description
Sets the passed values for the given property keys on the specified entity, using the security context of the current user.
set() accepts several different parameter combinations, where the first parameter is always a graph object. The second parameter can either be a list of (key, value) pairs, a JSON-coded string (to accept return values of the geocode() function) or a map (e.g. a result from nested function calls or a simple map built in serverside JavaScript).

Hint
When using the set() method on an entity that is not writable by the current user, a 403 Forbidden HTTP error will be thrown. In this case, use set_privileged() which will execute the set() operation with elevated privileges.

Examples

// Key-Value examples
${set(user, 'name', 'new-user-name', 'eMail', 'new@email.com')}
${set(page, 'name', 'my-page-name')}

// JSON examples
${set(this, geocode(this.street, this.city, this.country))}
${set(user, "{name: 'new-user-name', age: 42, eMail: 'new@email.com'}")}

// JavaScript example
${{
    var me = Structr.me;
    Structr.set(me, {name: 'my-new-name', eMail: 'new@email.com'});
}}

Search results for "set()"

set()

Sets the passed values for the given property keys on the specified entity, using the security context of the current user.
set() accepts several different parameter combinations, where the first parameter is always a graph object. The second parameter can either be a list of (key, value) pairs, a JSON-coded string (to accept return values of the geocode() function) or a map (e.g. a result from nested function calls or a simple map built in serverside JavaScript).

set(entity [, key1, value1, ... ])
set(entity, json)
set(entity, map)