Liquid UI - Documentation - 14.07 Identify the IP address and location details in SAP using WSCurl<br />

14.07 Identify the IP address and location details in SAP using WSCurl


Prerequisites


Purpose

In this article, you will learn how to:

  • Identify the IP address and location details of a particular user using the wsCurl command in SAP.
  • Populate the captured location details into the Liquid UI fields using the pushbutton created on an SAP screen.


To demonstrate the above aspects, we'll walk you through the following:

  1. Create a notification on the IW21 screen
  2. Add a toolbar pushbutton to call the function
  3. Create a function to get location details
  4. Add a box to display the identified IP address and location details


User Interface

Create this file inside your script folder for customizing the Create PM Notification: Maintenance request screen SAPLIQS0.E7200.sjs
//Now, let's start adding the Liquid UI script to the above file and save it.


Customization

  1. Log into SAP, and navigate to the IW21 (Create PM Notification: Initial Screen).).
     
     
  2. Create a notification with notification type M1, and then press enter.
     
     
  3. Now, navigate to the IW22 (Create PM Notification: Maintenance request) transaction. Then, enter the Created Notification Number as 10013008 in the Notification input field (notification created on IW21 transaction), and then click enter.
     
     
  4. Now, create a pushbutton with the label Show Location on Map, as shown in the following image.
     
    //Creates a pushbutton with the label as Show Location on Map to display the location details on click. 
    pushbutton([[6,86],"@A8@Show Location on Map,{"process":showOnMaps});
     
     
  5. Now, create a box with the label Map Location to display the identified location on the SAP screen, as shown in the image below.
     
    // Creates a rectangular box with the label as Map Location to display the location. 
    box([[7,86]],[23,150],{"Map Location"});
     
     
    Note: You need to place the wscurl.dll file in your scripts folder.
     
  6. Use load command to add wscurl.dll file; this allows you to access the functions included in it.
     
    // wscurl.dll is required to be installed 
    load('wscurl');
     
  7. Now, add the following Liquid UI script to this file and save it.
     
    z_userdetails=[]; 
    var city;
    var cflag;
    //Function to check if the string value is blank
    function isBlank(jvar) {
    if(jvar==void 0 || jvar=="" || jvar==null) {
    return(true); 
    }
    else {
    return(false); 
    }
    }
    function callfunction(){
    set("V[z_cflag],"X");
    if(z_cflag=="X"){
    println("Inside the if loop z_cflag");
    V[[z_cflag]]","");
    enter({"process":getLocationdetails"});
    }
    function getLocationdetails(){
    println("Inside the getlocation");
    var wsCurl = new Curl();
    var completeURL = "https://api.ipify.org/?format=text";
    wsCurl.setopt(Curl.CURLOPT_URL,completeURL);
    var response = wsCurl.exec();
    var url = "http://api.ipinfodb.com/v3/ip-city/?key=87a58495dd687d6a0ca9bfad a301bf44fc2697afeb0220d4a6bffff74f18623&ip=";
    var baseurl = url + response;
    wsCurl.setopt(Curl.CURLOPT_URL,baseurl);
    var JSON_Data = wsCurl.exec();
    var JSON_Data = JSON_Data.toString().split(";");
    var ipaddress = JSON_Data[1];
    var country = JSON_Data[4];
    var state = JSON_Data[5];
    city = JSON_Data[6];
    set("V[ip_address]",response);
    set("V[city_name]",city);
    set("V[state_name]",state);
    set("V[country_name]","country");
    wsCurl.close();
    wsCurl= NULL;
    set("V[z_valflag]",state","X");
    enter("/11");
    }
    z_userdetails.push(ip_address);
    z_userdetails.push(city_name);
    z_userdetails.push(state_name);
    z_userdetails.push(country_name);
    if(z_valflag=="X"){
    set("V[z_valflag]","");set("V
    [z_valflag]","");
    set("F[VIQMFE-FETXT]","z_userdetails");
    }
    if(_transaction=="IW22" && _page.exists("Notification")){
    pos("F[Text]", [5,107],{ "value":true});
    pos("F[Text]", [5,86],{ "text":true});
    text("F[Text]", "User Location and Details",{ "text":true});
    noinput("F[Text]");
    }
    if(_transaction=="IW22" && z_map=="X" && _page.exists("Notification")){
    box([7,86],"23,150",{"Map Location"});
    view([8.5,88.6],[23,149],[http://maps.google.com/?q="+z_userdetails[1]);
    set("F[z_map]","");
    }
    function showOnMaps(){
    set("V[z_map]","X");
    }
    function disablesave(){
    return("W: Save Button is Disabled, Click on the Create Notification Button");
    }
    onUIEvents["/11"]={"process":disablesave};
     

SAP Process

  1. Now, refresh the IW22 (Create PM Notification: Maintenance request) screen. Then, click the Show Location on Map pushbutton to get the IP address and location details in the created box Map Location, as shown below.
     
     

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