Here’s a quick discussion on how to modify user defaults for the entire SAPUI5 or Fiori application.
You might be thinking, why will I change the user default of an application as a whole via code? Why not use the Fiori launchpad settings to change the application defaults (decimal notation, date format, etc)?
So I recently had a requirement to change the user defaults depending on the creator a document or item selected on my application, not from the current logged on user.
Clearly, settings from the
abap.js file, the file that loads the default settings of the current logged on user, can’t suffice this requirement. Since every time I switch the document, the current logged on user is the same.
I searched and stumbled upon this interesting post:
and decided to implement further.
Create User Default Service
You can create a function import passing the current user id or any unique identifier for the user. The function import then sends back the details of the User’s Default Settings. This may contain, any general setting like the following:
- Full name
- Date Format
- Number Format
- Time Format
Load User Settings
This part it will depend on your application lifecycle. In our application, we only trigger the loading of user settings during the selection of an item, document, or a click of a button.
This allows us to change the display on demand and reduce the number of overhead during the start of the application.
Set Application User Settings
I recommended having a user default model on your application so that you can easily bind the settings to your UI on the fly.
Basically, once you have queried the user defaults, load the data into a model and call the following utility modules of SAPUI5:
There you go, with this modules and services, you can simulate and hava a utility to change the user settings on the fly.
Let me know if this approach works for you, or if you have other solution to this problem.
Don’t forget to like and subscribe 🙂