Getting Started with Kapsel – Part 7 — Settings
Settings
The settings plugin is used to exchange settings between the SMP 3.0 server and a Kapsel application. To demonstrate this, the settings plugin will be added to the Logger Sample and will enable the changing of the log level of the Kapsel app by making changes to the log settings from within the management cockpit. It also automatically uploads the log file to the SMP 3.0 server each time that app starts or resumes if the option to Log Upload is checked on the Client Logging dialog of a registration.
For additional details see the JavaScript file in a project that includes this plugin at
project_name\www\plugins\com.sap.mp.cordova.plugins.settings\www\settings.js
or the JS Documentation at Kapsel Settings API Reference.
The following steps will demonstrate this plugin.
- Change directory to LoggerDemo
cd C:\Kapsel_Projects\LoggerDemo cd ~/Documents/Kapsel_Projects/LoggerDemo
- Add the settings plugin to the LoggerDemo app.
cordova -d plugin add com.sap.mp.cordova.plugins.settings
- Copy the files to the platform directory by running
cordova -d prepare
- After adding the settings plugin, an exchange will occur each time that the application opens (not on a resume). During the settings exchange the log level specified for the application instance or registration and the log upload setting as set in the Management Cockpit is sent to the device. The settings plugin then acts on those values and sets the log level and performs a log upload.
Note, if you wish enable logs to be uploaded from the device when sap.Logger.upload() is called but do not wish the log to be uploaded each time a settings exchange occurs, comment out the sap.Logger.upload() call in C:\Kapsel_Projects\LoggerDemo\plugins\com.sap.mp.cordova.plugins.settings\www\settings.js and then call cordova prepare. Similarily if you do not wish the log level of the app to be set in the management cockpit, comment out the sap.Logger.setLogLevel call in settings.js.
Note, the automatic log upload performed by the settings plugin fails in SP06 on Android due to issue 1472020964 which is fixed in SP06 PL01. - Modify
www/plugins/com.sap.mp.cordova.plugins.settings/www/settings.js
and add the line
getLogLevel(); //updates the Log Level select to the value returned to the Kapsel app from the SMP 3.0 server
to the end of the success callback of sap.Settings.start (around line 78). This will update the Log Level select to the current log level received during the settings exchange.
- Use the Android IDE or Xcode to deploy and run the project.
Notice that the debug level is ERROR by default. Use the Management Cockpit to change the log level to WARNING and enable the automatic uploading of the log for a particular registration by clicking on the Client Log icon for a registration.
Note, the mapping between the SMP server log levels and the Kapsel log levels is mapped in the method setLogLevel in the following file.
www/plugins/com.sap.mp.cordova.plugins.logger/www/logger.js
- Hit the back button on Android to close the application. On iOS press the home button to send the app to the background. Press the home button twice quickly and press and hold on the Logger Demo icon until a minus sign appears. Click on it to close Logger Demo.
- Open Logger Demo and notice that the Log Level is now set to WARN. A new log file should also appear under Logs and Traces.
Note, if the log does not appear it may be due to issue 741025.
- In the Management Cockpit it is also possible to click on the log file and have it be downloaded to your computer. This would be useful if the SMP 3.0 server is running on a different machine than the Management Cockpit.
Updated for SMP 3.0 SP03
Updated for SMP SDK 3.0 SP04
I was trying this feature to the existing loggerDemo application.
About the modifying js file as you mentioned above. I have added "getLogLevel();" in sap.Settings.start as below. Is it correct?
F:\kapsel_projects\LoggerDemo\plugins\com.sap.mp.cordova.plugins.settings\www\settings.js
Also, what is difference between Application Log Level and Log Message at Level in the given "Logger Sample" screen?
Rgrds,
JK
I believe it should be after the sap.Logger.debug("Settings Exchange is successful"); line.
The sap.Logger has a log level that can be set. If it is set to Error which it is by default, logging a message at the debug level will have no effect.
Hope that helps,
Dan van Leeuwen
yes. it helped. Thanks a lot Dan.
Updated for SMP SDK 3.0 SP05
Updated for SMP SP06 SDK and SP05 Server.
Hi Daniel,
i was trying the setting plugin but getting the message "MAFLogonCoreCDVPluginJS functionality is not yet implemented" any help for this? my code is as below.
exchSettings: function() {
var connectionData = {
"keyMAFLogonOperationContextConnectionData": {
"keyMAFLogonConnectionDataApplicationSettings": {
"DeviceType": this.device.platform,
"DeviceModel": this.device.model,
"ApplicationConnectionId": "myhat"
},
"keyMAFLogonConnectionDataBaseURL": "SMP sercer path"
},
"keyMAFLogonOperationContextApplicationId": "application ID",
"keyMAFLogonOperationContextBackendUserName": "",
"keyMAFLogonOperationContextBackendPassword": "",
"keyMAFLogonOperationContextSecurityConfig": "",
"keySSLEnabled":"false"
};
sap.Settings.start(connectionData, function(mesg) {
sap.Logger.debug("Setting Exchange is successful " + mesg, "SMP_SETTINGS_JS", function(m) {}, function(m) {});
},
function(mesg) {
sap.Logger.debug("Setting Exchange failed" + mesg, "SMP_SETTINGS_JS", function(m) {}, function(m) {});
});
},
Thanks, Prem
There is an updated sample with a title of Settings using XMLHttpRequest Object
in the below document that maybe helpful. Note the metadata document shows the fields that can be updated.
Getting Started with Kapsel - Part 7 -- Settings (SP09+)
Hope that helps,
Dan van Leeuwen
hi Dan,
thanks for reply, with this process how do i check for feature enable or not, in the same we used to check with setting plugin using sap.Settings.isFeatureEnabled API ?
thanks, prem
I was hoping that seeing the underlying REST requests and the metadata showing which fields are updateable would help.
What are you trying to accomplish by using the Settings Exchange plugin?
I imagine you can continue to use sap.Settings.isFeatureEnabled API.
Regards,
Dan van Leeuwen
Hi Dan,
i am trying to explore feature restriction policy (plugin enable/disable) option in SMP for which i need the setting plugin to exchange the settings among client and SMP server also setting plugin provides API to check for enable disable plugin from SMP that tells client that whether plugin can be used or not.
thanks, prem
Have you looked at the section on Feature Restriction? Perhaps the example there will help.
Getting Started with Kapsel - Appendix D -- Security Part 1
Regards,
Dan van Leeuwen
Hi Daniel,
yes i did follow this already but with no luck as this blog is written for WEB IDE and i guess this issue is happening in web IDE,
actually i ma trying this in SAP WebIDE with HCPms server i have added logon plugin, while launching the application call logon and get resisted with server i am not calling the plugin explicitly, however i have tried calling the logon plugin explicitly to get the context of the app and security config , but i get the same error (MAFLogonCoreCDVPluginJS functionality is not yet implemented) on logon plugin as well, i think this is happening with web IDE, did you try this in SAP web IDE.
thanks, Prem