Set User Properties¶
Description¶
Before updating the BackendlessUser
object you must set new values or new properties locally in the application using the operation described in this topic. Then you have to use the Update User Object operation to send the locally saved data to Backendless servers to update the Users
data table.
Important
When setting or updating a user property, the values must be of "primitive" data types (boolean, string, number, date). To assign a non-primitive value, use the Data relation API .
When registering a new user, the methods below can be used on the new BackendlessUser
object. When updating an existing user, the BackendlessUser
object representing the user must be retrieved from the server (either via login or the data object retrieval APIs).
Method¶
// set property value. The property name is the value of the "key" argument
public void Backendless.UserService.setProperty( String key, Object value )
// adds properties to the existing ones
public void Backendless.UserService.putProperties( Map<String, Object> properties )
// removes all existing properties (including the built-in ones such
// as email and password, and sets the provided properties
public void Backendless.UserService.setProperties( Map<String, Object> properties )
Return Value¶
None.
Example¶
The example below sets a new value "342-821-3802"
for the property "phoneNumber"
locally in the application.
If this property is new and does not exist in the Users
data table, then upon the update operation a new column is created with the specified value. This behavior is available only if the Dynamic Schema Definition option is activated.
// Update an existing property
BackendlessUser user = new BackendlessUser();
user.setProperty( "phoneNumber", "342-821-3802" );
// Update multiple existing properties
Map<String, Object> properties = new HashMap<>();
properties.put( "email", "jack@yourmail.com" );
properties.put( "password", "somePassword" );
properties.put( "name", "Jack" );
user.setProperties( properties );
// Add new properties with values to the BackendlessUser object
Map<String, Object> properties = new HashMap<>();
properties.put( "email", "jack@yourmail.com" );
properties.put( "password", "somePassword" );
properties.put( "name", "Jack" );
user.putProperties( properties );