Liquid UI - Documentation - 10.10 Get login username and role using _client

10.10 Get login username and role using _client


Prerequisites


Purpose

Learn how to get the username and role of the current user using the _client command. Here, we have loaded the User Catalog file into the directory folder to create and assign a script directory for each group of users logged into the SAP to assign/change Directory 1 of the scripts based on the group assignment for an SAP User/Role.

 
 
Note: You need to place the USER_CATALOG.sjs file in your scripts folder, and it must be loaded in the SAPLSMTR_NAVIGATION.E0100.sjs file.
 
 

User Interface

//Create the files USER_CATALOG.sjs and SAPLSMTR_NAVIGATION.E0100.sjs inside your script folder for customizing the SAP Easy Access screen
//Now, let's start adding the Liquid UI script to these files and save them.

  1. Logon to SAP. On the appeared SAP Easy Access screen, you can assign a script directory for each group of users logged into the SAP. Add the following Liquid UI code to the USER_CATALOG.sjs and SAPLSMTR_NAVIGATION.E0100.sjs files.

     

    //USER_CATALOG.sjs

    User Group Corresponding to Directory1

    var GROUP_CATALOG_ARRAY = [
    {
    "groupname":"G1",
    "d1":"c:\\guixt\\G1\\d1",
    "tcode":"/nsmen"
    },
    {
    "groupname":"G2",
    "d1":"SAPWR:Z.GUIXT",
    "tcode":"/nva01"
    },
    {
    "groupname":"G3",
    "d1":"\\\\guixt.com\\usr\\SYNACTIVE\\Accounts\\Sempra\\M&I Group\\Consulting\\Scripts\\LC-FOS-DOC_scripts",
    "tcode":"/nva01"
    }
    ];
    **/

    var GROUP_CATALOG_ARRAY = [
    {
    "groupname":"G1",
    "d1":"c:\\guixt\\G1\\d1",
    "tcode":"/nsmen"
    },
    {
    "groupname":"G2",
    "d1":"\\\\guixt.com\\usr\\SYNACTIVE\\Accounts\\Sempra\\M&I Group\\Consulting\\Scripts\\LC-FOS-DOC_scripts",
    "tcode":"/nva01"
    }
    ];


    /**

    User assignment to *one* group

    var USER_CATALOG_ARRAY = [
    {
    "user":"800/umang",
    "group":"G1"
    },
    {
    "user":"800/zac",
    "group":"G1"
    },
    {
    "user":"800/rumi",
    "group":"G2"
    }
    ];
    **/


    var USER_CATALOG_ARRAY = [
    {
    "user":"800/umang",
    "group":"G1"
    },
    {
    "user":"800/zlee",
    "group":"G3"
    },
    ];


    /**

    SAP Role assignment to *one* group

    var ROLE_CATALOG_ARRAY = [
    {
    "role":["Z_GUIXTNEW"],
    "group":"G1"
    },
    {
    "role":["ZGUIXTROLE2"],
    "group":"G1"
    }
    ];
    **/


    var ROLE_CATALOG_ARRAY = [
    {
    "role":["Z_GUIXTNEW","Z_GUIXTRFC4"],
    "group":"G1"
    }
    ];




    /**
    Load User Catalog Call Function
    **/

    //Function to load the user catalog
    function load_user_catalog(group_array,user_array,role_array) {
    var current_client_user = _client + '/' + _user.toLowerCase().replace(/^\s+|\s+$/g,"");

    if(user_array && user_array.length > 0) {
    for(i = 0; i<user_array.length; i++) {
    if(user_array[i].user == current_client_user) {
    for(j = 0; j<group_array.length; j++) {
    if(user_array[i].group == group_array[j].groupname) {
    if(group_array[j].d1) {
    enter(group_array[j].tcode +"/d1=" + group_array[j].d1);
    break;
    }
    }
    }
    break;
    }
    }
    }

    if(role_array && role_array.length > 0) {
    var Z_ROLES = [];
    call('BAPI_USER_GET_DETAIL', {"in.USERNAME":"&V[_user]","table.ACTIVITYGROUPS":"Z_ROLES"});
    for(i = 0; i<role_array.length; i++) {
    var role_match_count = 0;
    for(m = 0; m <role_array[i].role.length; m++) {
    for (j = 0; j < Z_ROLES.length; j++) {
    var z_userrole = Z_ROLES[j].toString().substring(0,30);
    if(role_array[i].role[m].toLowerCase().replace(/^\s+|\s+$/g,"") == z_userrole.toLowerCase().replace(/^\s+|\s+$/g,"")) {
    role_match_count++;
    }
    }
    }
    if(role_match_count == role_array[i].role.length) {
    for(k = 0; k<group_array.length; k++) {
    if(role_array[i].group == group_array[k].groupname) {
    if(group_array[k].d1) {
    enter(group_array[k].tcode +"/d1=" + group_array[k].d1);
    break;
    }
    }
    }
    break;
    }
    }
    }
    }

    //Call function once
    if(!load_user_catalog_flag) {
    load_user_catalog_flag = 'X';
    load_user_catalog(GROUP_CATALOG_ARRAY,USER_CATALOG_ARRAY,ROLE_CATALOG_ARRAY);
    }
  2. Use load command to add the user_catalog.sjs.

     //SAPLSMTR_NAVIGATION.E0100

    // Calls the user_catalog.sjs file to customize the SAP screen. 
    load('user_catalog.sjs');
     

    SAP Process

    1. Refresh the SAP Easy Access screen, and click enter to load the User Catalog file. This will create and assign a script directory for each group of users logged into SAP, as shown in the image below.
       
       

Can't find the answers you're looking for?