Liquid UI - WS Reference Library

System Variable: _user in determining authorizations using SAP Roles and Profiles


Prerequisites


Runs On

  SAP GUI Android iOS WM Web
Direct Connect          
Liquid UI Server Connect        


Purpose

Utilizing the below scripts where we call the Function Module 'BAPI_USER_GET_DETAIL', we can determine user authorizations based on their roles.


User Interface

Log into SAP and on the SAP Easy Access Screen click on the ‘Get Roles’ toolbar pushbutton.


 

The function will call the ‘BAPI_USER_GET_DETAIL’ function module and the output is printed on the Console (Cornelius Output).



Liquid UI Script

//SAPLSMTR_NAVIGATION.E0100.sjs


//*******************************************************************************************************************
//Purpose: Function is called to validate if the variable holds blank or null value
//*******************************************************************************************************************
function isBlank(jvar){
    if(typeof jvar == 'string') {
        jvar = jvar.trim();
    }
    return(jvar == 'undefined' || jvar == null || jvar == "" || jvar == void 0);
}

//*******************************************************************************************************************
//Purpose: Function is called to remove blank spaces
//*******************************************************************************************************************
function trim(str){
    str = str.replace(/^\s+|\s+$/g,"");
    return str;
}

//*******************************************************************************************************************
//Purpose: Function is called to read user SAP role and profile
//*******************************************************************************************************************
function getAuthorizations(){
   call('BAPI_USER_GET_DETAIL', {"in.USERNAME":"&V[_user]","table.ACTIVITYGROUPS":"Z_ROLES",'table.PARAMETER':'arParam'});
}

//*******************************************************************************************************************
//Purpose: Function is called to see if current user has the roleName match
//*******************************************************************************************************************
function roleExists(roleName){
   for (i = 0; i < Z_ROLES.length; i++)   {
      var z_userrole = Z_ROLES.toString().substring(0,25).trim();
      if(z_userrole == roleName) {
         return true;
      }
   }
   return false;
}

//*******************************************************************************************************************
//Purpose: Function is called to see if current user has the tableLayoutRegion match
//*******************************************************************************************************************
function tableLayout(tableLayoutRegion) {
   for (i = 0; i < arParam.length; i++)   {
      var z_layout = arParam.toString().substring(0,16).trim();
      if(z_layout == tableLayoutRegion) {
         layout_check_value=arParam.toString().substring(17,30);
         layout_check_value=layout_check_value.trim();
         return layout_check_value;
      }
   }
   return 'DEFAULT';
}

//*******************************************************************************************************************
//Purpose: Main Function to test and print the output on the console
//*******************************************************************************************************************
function CheckAuthorizations(){    // Test for role
       getAuthorizations();
       checkAccess=roleExists("SAP_BC_DWB_ABAPDEVELOPER");
       tableLayoutStyle=tableLayout("WLC");
    // Below println's to print the values of the variables on the console output
       println('\n------checkAccess:'+checkAccess);         
       println('\n------tableLayoutStyle:'+tableLayoutStyle);    
}

pushbutton( [TOOLBAR], "@F8@Get Roles", "?", {"process":CheckAuthorizations});