on 07-10-2014 6:17 AM
Hi All,
I want to return an employee entity for the currently logged in User for a UI5 app. Now since my employee entity has a username filter, I could call service/employees(filter=Username eq 'myuname') but I'm not sure how easy it is for a UI5 app to generically work out the user id since authentication could be done in numerous ways in the browser.
Hence I want to provide the ui5 development a service to return an employee entity for the current logged in user.
Question: How should I do this?
Option a: Create a function import called GetCurrentLoggedInEmployee that returns an Employee entity.
This is very obvious and probably what I'm thinking is the right way.
Option b: Call a generic Gateway service that exists that I don't know about that returns the username???
Option c: ??? Pretty sure I can't navigate from an Employees entity so struggling to think of other nice options.
Please note: I haven't looked at how Fiori apps do this which could hold the key.
Thanks for any advice you can give,
Matt
Hi Matt,
Option A looks perfect for me but same can be done by implementing get_entity for employee entity. now you can make userID as key and while querying, you can pass it as
EmployeeCollection(UserID=' ') and then just ignore the key passed as you will be referring userid as
sy-uname. This way you can make it generic.
2nd option, there is SICF service /sap/bc/ui2/start_up which returns all the required logged in user details. you can query with /sap/bc/ui2/start_up in GW Client transaction to verify the details. but as this is not OData service but SICF service returning data in the fromat of JSON, you may want to execute ajax call to get the details.
Regards,
Chandra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Creating a new entity to return just the sy-uname's information would be very simple. If you do not want to pass empty username, you have two options. Return the information in get_entityset. Other option is to use a function import, which will return a single record.
I checked in the FIori and it uses the '/sap/bc/ui2/start_up' service.
Hi Matt,
And also if you just want to display logged in user details without Ajax call to start_up service then you can use below coding in UI5 application.
basically it will call startup SICF service only.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<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="https://sapui5.netweaver.ondemand.com/resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.ui.commons"
data-sap-ui-theme="sap_goldreflection">
</script>
<!-- add sap.ui.table,sap.ui.ux3 and/or other libraries to 'data-sap-ui-libs' if required -->
<script>
var oUser = sap.ui2.shell.getUser();
oUser.load({}, function(){
var fullName = oUser.getFullName();
var userID = oUser.getId();
//alert(fullName);
//alert(userID);
//create the ApplicationHeader control
var oAppHeader = new sap.ui.commons.ApplicationHeader("appHeader");
//configure the branding area
oAppHeader.setLogoSrc("http://www.sap.com/global/images/SAPLogo.gif");
oAppHeader.setLogoText("User Details");
//configure the welcome area
oAppHeader.setDisplayWelcome(true);
oAppHeader.setUserName(fullName);
//configure the log off area
oAppHeader.setDisplayLogoff(true);
oAppHeader.placeAt("content");
},
function(){
alert ('Error');
});
</script>
</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>
and as Krishna rightly mentioned these user services are being used in Fiori.
Regards,
Chandra
User | Count |
---|---|
85 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
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.