Liquid UI - Documentation - 22.06 search_option function

22.06 search_option function


Prerequisites


Purpose

The search_option function enables users to search digital objects in the collection through a simple search.
When the user enters the search terms, the computer finds the information (In the following example, when the user enters the order number, it runs the function and displays the order number).
You will learn how to use the search_option function to replicate an option used in Classic GuiXT. The search_option function takes two strings:

  1. The string you want to search in.
  2. The word you want to search for within the available objects.
 

The function returns the next word after the word you searched for. If the word you are searching for is not in the original string, it returns a blank string.
This is very useful for scenarios like extracting an order number from a collection of messages. To demonstrate the search_option function, we have taken the VA02 screen as an example and will walk you through the following steps:

  1. Add a sample success message
  2. Add a message command
  3. Add a function for the search option
 

Customization

 

//Create this file inside your script folder for customizing the Change Sales Order: Initial Screen SAPMV45A.E0102.sjs
//Now, let’s add the Liquid UI script to the above file and save it.

 
  1. Add a sample success message to save the order number.
     
    //Deletes the Image container on the screen
    z_message = "Order 124321 was saved."
    // order_num will hold the value of 124321, searching for "Order" in z_message
    order_num = search_option(z_message,"Order")
     
  2. Add a message to display the order number on the screen.
     
    // Print out the message on the screen
    "Order Number:"+order_num);
     
  3. Add a function to retrieve the order number from the message.
     
    //This function is used to retrieve the order number from the user-entered message 
    //It will return the next word after the search word
    //It will return an empty string when the word you are searching for is not the original string
    function search_option(str1, search){ var arr = str1.split(" "); for (var i = 0; i<arr.length; i++){ if(arr[i] == search){ if(i+1 != arr.length){ return arr[i+1]; } } } return "";
     

SAP Process

  1. Enter the Order number and click on the Search button. Then the requested Order ID will be displayed at the bottom of the SAP screen, as shown below.
     
     


Next Steps

Reorder table values to remove empty rows
Learn how to remove all the empty rows in a list and move the populated rows in Order.

5 min

This article is part of the Conditional scripts tutorial.


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