Liquid UI - WS Reference Library

search_option function


Prerequisites


Runs On

  SAP GUI Android iOS WM Web
Direct Connect          
Liquid UI Server Connect


Purpose

The search_option function is used to replicate an option used in Classic GuiXT. The search_option function takes two strings; the first is the string you want to search in and the second is the word you want to search for. 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, then it returns a blank string. This is very useful for scenarios like extracting an order number from a successful saving message.


User Interface

Log into SAP and see the message at the bottom of the screen.


Liquid UI Script

//SAPMV45A.E0102.sjs

// Sample success message
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");
// Print out the message to the screen
message("Order Number:"+order_num);
// This function is used for the "search" option in Legacy
// It will return the next word after the searching word
// It will return an empty string if not found
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 "";
}