on 11-29-2022 1:30 PM
Users have the option to store personal preferences like time format, date format in the Fiori Launchpad. (Maintaining Your Language and Regional Settings)
These settings are stored in the sap table USR01.
In UI5 Applications we can access these informations via
sap.ui.getCore().getConfiguration().getFormatSettings()...
But how do we apply these settings to the app/to the controls in the app... ?
Language is possible via:
sap.ui.getCore().getConfiguration().setLanguage(sLanguage);
But how about formatting Date Formats/Time Formats/... ?
Normally the sap.ui.model.type is used but this model type gives a damn about the user preferences...
Ignoring sap.ui.model.types and using custom formatters also feels wrong....
Is there an offical documentation i missed ?
Thanks in advance
-----EDIT-----
I can get/set these options via:
var sDateFormat = sap.ui.getCore().getConfiguration().getFormatSettings().getDatePattern("medium");
sap.ui.getCore().getConfiguration().getFormatSettings().setDatePattern("medium", sDateFormat);<br>
like Margot Wollny mentioned, but that's not enough for controls to adapt to these settings.
For example the following sap.m.ObjectAttribute doesn't care about these settings... (attachment>UploadedAt contains an JS Date Object)
<ObjectAttribute title="{i18n>uploadedAt}" text="{ path: 'attachment>UploadedAt', type: 'sap.ui.model.type.DateTime', formatOptions: { style: 'medium'}}" class="sapUiTinyMarginEnd"/><br>
I set these settings before i instantiate the app. (Language(i18n) works fine/formattings not)
What am i missing ?
UI5 Version: 1.90.7
Environment: Fiori Launchpad --> Web UI (WCF) --> thtmlbx:htmlIsland(iframe) --> Custom UI5 App
-- Solution --
The answers of Margot Wollny and Jun Wu are both correct.
Normally nothing needs to be consirdered as a developer. The settings are applied automatically, as Jun Wu mentioned. If your application is running in an different "sap.ui.getCore()" instance (for example an iframe) make sure to correctly transfer these settings.
You can either use
sap.ui.getCore().getConfiguration().getFormatSettings().setLegacyDateFormat("9"); //1-9, A-C
sap.ui.getCore().getConfiguration().getFormatSettings().setDatePattern("short", "dd-MM-YYYY"); //YYYY-dd-MM or sth. else
you can still run your app with launchpad(for the iframe), which will take care of the format
https://help.sap.com/saphelp_uiaddon10/helpdata/en/53/7758e0deb0477386ea400c915073b3/frameset.htm
second option, in your ui5 app, make ajax call to /sap/bc/start_up, which will give you the format(date, time, number) you need, then set to the ui5 framework by yourself.
setLegacyNumberFormat
setLegacyTimeFormat
setLegacyDateFormat
fiori launchpad is calling the same methods to set format, if I am not wrong.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Jun,
thanks for your ideas. I expressed myself wrong here. Iam able to read the user settings from the FLP and apply them to my iframe/"sap.ui.getCore() Instance" before instantiating the application. The language ist set accordingly and is also reflected in the controls/i18n changes. The format settings are also set, but have no effect on the controls. I adjusted my question.
User | Count |
---|---|
77 | |
9 | |
8 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.