Skip to content

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

// adding a new property
public void AddProperty( string key, object value )

// changing value for an existing property
public void SetProperty( string key, object value )

// if a property from "newProps" exists in BackendlessUser object,
// it is updated, otherwise, it is added to the object.
public void PutProperties( Dictionary<string, object> newProps )

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.

// login user and put user object into currentUser variable
 var currentUser = Backendless.UserService.Login("my_email@gmail.com", "my_password");

 currentUser.SetProperty("newProperty1", propertyValue1);
 currentUser.AddProperty("newProperty2", propertyValue2);
 currentUser.PutProperties( new Dictionary<string, object>{ { "newProperty3", propertyValue3 } } ); // you can set multiple properties
 currentUser.Properties = new Dictionary<string, object> { { "newProperty4", propertyValue4 } }; // replace all properties with new value
currentUser.Properties["newProperty1"] = propertyValue4; // replace only "newProperty1"

Backendless.UserService.Update(currentUser); // update user object in database