Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

SAPUI5 - User Login and Corresponding Employee ID

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.

Tags:
Not what you were looking for? View more on this topic or Ask a question