on 04-16-2014 9:31 AM
Hi experts,
I have problem, when I try to get the ID from the loged user in SAPUI5.
I have tried:
1.
var oUser = sap.ui2.shell.getUser();
var userId = oUser.getId();
Here I have error: Uncaught TypeError: Cannot read property 'shell' of undefined
2.
var oUser = new sap.ushell.services.UserInfo();
var userId = oUser.getId();
Here I have error: Uncaught TypeError: Cannot read property 'services' of undefined
I will appreciate if you can show me an example or to guide me, beacause I don't know what I'm doing wrong.
BR,
Simona
Hi Simona,
You can retrieve the logged in Username by calling the shell service " sap.ushell.Container.getService("UserInfo").getId() ". Its mentioned the UI5 Api Refrence page (SAPUI5 SDK - Demo Kit).
Regards,
Bince
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am getting sap.ushell.Container.getService("UserInfo").getUser() as undefined
HI,
if you want to access the user detail when you are running your application in launchpad. then you can retrieve current user detail by adding following code snippet:
sap.ushell.Container.getUser()
I hope this is enough to get a user related object. then further detail about the user can be retrieved.
Regards,
Khushdeep
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Just like what you have tried , you can use :
var oUser = sap.ui2.shell.getUser();
oUser.load({}, function() {
var userID = oUser.getId();
}
and you need to do this inside your index.html:
<script src="/sap/public/bc/ui2/services/sap/ui2/srvc/error.js"></script>
<script src="/sap/public/bc/ui2/services/sap/ui2/srvc/utils.js"></script>
<script src="/sap/public/bc/ui2/shell-api/sap/ui2/shell/startup.js"></script>
Thanks,
Mahesh Z.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Simona,
Solution 2: create one oData in SEGW to fetch currrent user then you can read the odata in your SAPUI5 application in any event like oninit () or any other function.
use the code write : sy-UNAME. in class or RFC
Regards
Sathish Mani
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
None of the above methods worked for me. I am getting
Uncaught (in promise) TypeError: Cannot read property 'Container' of undefined
Any idea?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I could not get the user id, I have tried in the following ways:
1. sap.ui2.shell.getUser ();
2. sap.ushell.Container.getService (" UserInfo ");
3. adding the scripts to the index file
4. with xmlHttp
5. sap.ui.require ([ 'sap / ushell_abap / bootstrap / abap' ], ...
but nothing works for me, some give me the error "of undefined", others print "default_user". but not the user id, it's something like "S0021 ..."
I am working with SAP Fiori Cloud
I appreciate your collaboration
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,you also can get all the system information (user Id, fullname, system, ...) from the config.
sap.ui.require([
'sap/ushell_abap/bootstrap/abap'
], function () {
var sysinfo = window["sap-ushell-config"].services.Container.adapter.config;
console.log(sysinfo.id);
});
Regards,
Mario
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Simona,
the easiest way would be to do an ajax request to an xsjs service and ask the Session API for the logged in user or if you have SAML enabled you can also verify that from the XSJS side.
check out the documentation here.
http://help.sap.com/hana/SAP_HANA_XS_JavaScript_Reference_en/$.Session.html
hope this helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Simona,
Just in case that you are still looking for an answer - if you need just the username, then create a XS service (.xsjs) :
$.response.contentType = "application/json";
var output = "";
var userName = $.session.getUsername();
output = '{"username":"'+userName+'"}';
$.response.setBody(output);
and call it in your view via an $.ajax call.
Greetings from Sofia,
Martin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Where r u hosting your Ui5 app? ABAP or any other java server?
The Ui2 scripts will work only in case the app is hosted on ABAP with the Ui5 Add-On)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Simona,
I guess you need to add below js files,
<script src="/sap/public/bc/ui2/services/sap/ui2/srvc/error.js"></script>
<script src="/sap/public/bc/ui2/services/sap/ui2/srvc/utils.js"></script>
<script src="/sap/public/bc/ui2/shell-api/sap/ui2/shell/startup.js"></script>
<script src="/sap/public/bc/ui2/shell-api/sap/ui2/shell/shell.js"></script>
Regards,
Chandra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.