Liquid UI - Documentation - 23.23 User Validation with RFC call

23.23 User Validation with RFC call


Prerequisites

Purpose

The article details how to check the existence of a username by calling the BAPI_USER_EXISTENCE_CHECK function, based on the SAP Easy Access screen. Here, we’ll perform the following actions:

  1. Delete the image container on the SAP Easy Access screen
  2. Add an input field to enter the user name
  3. Add a push button to execute the process
  4. Add functions to validate spaces, trimmed strings, and blank strings, call Bapi, and display results

User Interface

//Create the file SAPLSMTR_NAVIGATION.E0100.sjs inside your scripts folder for customizing the SAP Easy Access screen
//Now, add the Liquid UI script to the above file and save it.

Customization

  1. Delete the image container on the SAP Easy Access screen using del().
     
    // Deletes the image container on the SAP screen
    del("X[IMAGE_CONTAINER]");
    
     
     
  2. Add an input field labeled User name to enter the user name.
     
    //Creates an input field to enter the user name
    inputfield([1,0],["Username"],[1,10],{"name":"z_user_name","size":"15"});
    
     
     
  3. Add a push button labeled Check User Exist to execute the z_fmCallGetData process on click.
     
    //Creates a push button to execute the process
    pushbutton([3,1],["Check User Exist"],"?",{"size":[2.20],"process":z_fmCallGetData});
    
     
     
  4. Add a function to remove blank spaces from variable values.
     
    //Function to remove blank spaces
    String.prototype.trim = function() {
       return this.replace(/^\s+|\s+$/g,"");
    }
    
  5. Add the getString function to return the trimmed string.
     
    //Function to return trimmed string
    function getString(strInput) {
       return(typeof(strInput) == 'undefined' || strInput == 'undefined')? "" : 
    strInput.toString().trim();
    }
    
  6. Add the isBlank function to check for blank string.
     
    //Function to check for blank string
    function isBlank(strInput) {
       var strVal = getString(strInput);
       var blank = strVal == "";
       return blank;
    }
    
  7. Add the z_fmCallGetData function to call Bapi and display results.
     
    //Function to call Bapi and display results
    function z_fmCallGetData() {
       rfcresult = call('BAPI_USER_EXISTENCE_CHECK',{'in.USERNAME':'&V[z_user_name]','out.RETURN':'z_return'});
       if(rfcresult.rfc_rc != 0){
          // Cannot Call RFC for any reason
          // RFC call was *NOT* successful.
          // Displays message to user that rfc cannot be called (you can use the content of rfcresult.rfc_key)
          message('E:Error! RFC call failed to return data');
          enter("?");
          goto SCRIPT_END;
       } else{
       
       // RFC Call was successful
       if(!isBlank(z_return)){
          set('V[z_user_exist]',z_return.substring(24,60));
       }
       
       message('S:'+ z_user_exist);
       set('V[z_user_name]','');
       enter("?");
       SCRIPT_END:;
       }
    }
    

SAP Process

  1. Refresh the SAP interface and input the username. Then, click on the Check User Exist push button. Upon successful verification, a confirmation message stating that "User (divya) exists" will be displayed, as shown below.
     
     
  2. If the RFC call is unsuccessful due to any of the following conditions:
    • An exception is encountered
    • The specified username is not present
    • The entered username is not valid
    An error message Error! RFC call failed to return data is displayed at the bottom of the SAP screen, as shown below.
     
     

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