on 04-05-2016 1:26 PM
Hi,
I want to capture the logged in user and it's corresponding employee ID stored in HR Table.
I have successfully captured the login user and have built the oData to fetch the employee ID based on login ID.
However, I am not able to pass the login ID (captured as global variable in index.html) to the other controller.
here is the code to capture login ID in my Index file.
<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>
var oUser = sap.ui2.shell.getUser();
oUser.load({}, function() {
userID = oUser.getId(); // HERE I AM DECLARING userID AS A GLOBAL VARIABLE
}, function() {
alert('Error');
});
</script>
Now I want to get the value of the global variable userID in onInit function of my controller file so that I can make my oData call.
onInit : function() {
console.log("User ID"+userID); //userID IS NOT VISIBLE HERE
},
But I am not getting the value in userID.
Console is giving the message that userID is not defined.
Any help would be highly appreciated.
Regards,
Firoz.
load is an async function, which means it's callback function is probably ran after your controller's onInit. You could either place a call to the odata call function within the load's callback or use a promise to run it. You could also use a model to store the user info.
Regards,
Jamie
SAP - Technology RIG
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sap.ui.controller("Portal.Main", {
onInit : function() {
oUser.load({}, function() {
var userID = oUser.getId();
jQuery.proxy(this.functionToCall(userID), this)
}, function() {
});
}
});
Regards,
Firoz.
User | Count |
---|---|
88 | |
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.