Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The user profile now supports custom properties in addition to the existing ones. Custom properties can be set either on the backend from the UserProfileBT.cls, or on the frontend, from the UserProfile.ts class. Since custom properties are stored as a JSON object, you can have several custom property types (int, char, arrays etc.).


Methods

The following methods have been made available for manipulating the custom properties in the user profile:


Backend (UserProfile.cls):

  • SetCustomProperty
  • GetCustomProperty
  • DeleteCustomProperty
  • GetAllCustomProperties
  • DeleteAllCustomProperties


All of the above methods can be called from the frontend using invokeServerTask. They all accept as input a custom serializable parameter which contains the following extra parameters (in addition to the existing UserProfileaParameter):

  • CustomPropertyName - character field used when specifying a single property to fetch/delete
  • CustomPropertyObject - JSON object used when returning one or more properties to the frontend; also used when saving one/more properties to the database


Frontend (UserProfile.ts) - namespace: akioma.swat.UserProfile

On the frontend, we have the following .ts class: UserProfile.ts. Here, the following functions are available:

  • saveCustomLocalProfileProperty(Object) - takes an object as input and stores the given custom properties in the vuexStore; if any properties are already present, they will be updated
  • removeCustomLocalProfileProperty(key) - takes a key as input and removes the custom property from the vuexStore
  • removeCustomLocalProfileProperties() - removes all custom properties from the vuexStore
  • loadCustomLocalProfileSettings() - returns all the custom properties stored in the vuexStore
  • loadCustomLocalProfileSetting(key) - returns a vuex custom property by the given key
  • loadFromServer() - triggers a manual reload of the user profile from the server
  • setProfileAutoStore(autoStore) - allow setting the profile autoStore property; values: 'onChange'  or 'onLogout'; this determines if the user profile is saved after every change or only on logout
  • getProfileAutoStore() - returns the current profile autostore
  • saveToServer(showSuccessMessage?, methodName?, oData?) - allows saving the whole user profile or a custom property on the backend; when methodName and oData are not specified, it saves the whole profile;


NOTE: Calling one of the functions above for storing/deleting custom properties does not automatically save the profile to the database. This is determined based on the profile autoStore property. Only if this is set to 'onChange' will custom properties be automatically saved in the database.


Saving custom properties

IMPORTANT: If only one custom property needs to be saved (either from the frontend or backend), sending the whole user profile is not required. You only need to send the desired property.

From the backend, you can call the 'SetCustomProperty' method and give it the new property in the CustomPropertyObject parameter. It will be merged with the existing custom properties in the profile.

From the frontend, a manual save can be triggered using the saveToServer function.

saveToServer(showSuccessMessage, methodName, oData)

Here, all parameters are optional. If none are specified, the whole user profile is stored.

This was extended with the methodName and oData parameters to allow for more control when saving a custom property.



Testing

For testing this, there is a new sample dialog: UserProfileCustomPropertySampleDialog. This dialog is accessible from the Samples desktop. Here you can set/delete properties. 

From here, properties are automatically saved on the backend and then reloaded in the vuexStore.

Image Added


NOTE: Since this dialog is only a sample dialog, there are some limitations here:

You can only set custom properties for your user profile.

You can only set property values to string.

In order to test this, the current user needs to be a developer, since access is determined based on the 'CanUseDeveloperTools' token.

By default, this is only enabled for the Developer user group.