Liquid UI - Documentation - 23.11 Search value in an array

23.11 Search value in an array


Prerequisites

Purpose

You can search for a value in an array using the custom find function. To demonstrate this process we are considering the SAP Easy Access screen as an example and walk you through the following steps:

  1. Delete the image container on the SAP Easy Access screen
  2. Add an input field to enter the value
  3. Add a push button to execute the process 
  4. Assign values to the variable
  5. Add a function to search the value in an array

User Interface

//Create the file SAPLSMTR_NAVIGATION.E0100.sjs inside your scripts folder for customizing the SAP Easy Access screen 
//Now, let's 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 the del command.
     
    //Deletes the image container on the SAP screen
    del("X[IMAGE_CONTAINER]");
    
     
     
  2. Add an input field labeled Taxable State where users can enter values of the stateArray.
     
    //Creates an input field to enter the value
    inputfield ([2,4], "Taxable State", [2,18],{"name":"z_state", "size":2});
    
     
     
  3. Add a push button labeled Validate State to validate the value entered in the Taxable State input field.
     
    //Creates a push button that executes the function on click
    pushbutton([4,4], "Validate State",{"size":[1,15], "process":validate_state});
    
     
     
  4. Create a variable and assign values to the variable.
     
    //Creates a variable and assigns values to it
    var stateArray = ["AK","FL","NV","NH","SD","TN","TX","WA","WY"];  
    
     
  5. Add the validate_state function to search for the value in an array and to display the message. 
     
    //Function that returns true or false if the search element is found in the array
    Array.prototype.find = function (p){
        for(i=0;i<this.length;i++)    if(this[i] == p) return true;
        return false;
    }

    function validate_state(){
        if(stateArray.find(z_state)){   
            return('S: Value Present');
    }
    }
    else{
    return('E: Please enter taxable state');
    }
    }
     

SAP Process

  1. Refresh the SAP screen and enter the value in the Taxable State input field. Then, click on the Validate State push button. If the provided value is valid, a success message appears at the bottom of the screen, as shown below.
     
     
  2. If the entered value is invalid, an error message will appear stating Please enter taxable state, as shown in the image below.
     
     

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