cancel
Showing results for 
Search instead for 
Did you mean: 

udf Required to get the string before "%" in HCI

anurag_sinha3
Participant
0 Kudos

Hi

I need a udf (Groovy Script)to fetch all the value in string which comes before "%"

for eg if the value is coming "CRN-YB20-DNB-SEPSDK%3Fcomp%3Dmp .. then fetch the value before 1st "%".

so result will be CRM-XB10-DNB-SEPSDK.. (total length of this string is 24 char)

note - % may or may not come in string

Accepted Solutions (1)

Accepted Solutions (1)

sanjali07
Participant
0 Kudos

Hello,

You could use the tokenizer for this,

import com.sap.it.api.mapping.*;
def String GetBeforeToken(String input, String token){               
   return input.tokenize(token)[0]; 
}

So here the token value would be a Constant "%"

And if there is no token in the input, it will return the string as is in the output.

Kind Regards

Sanjali

anurag_sinha3
Participant
0 Kudos

thank but is it possible to get all value in Queue ..if so then please help me to implement the logic

for eg CRN-YB20-DNB-SEPSDK%3Fcomp%3Dmp then output will be CRN-YB20-DNB-SEPSDK

Fcomp

Dmp

Answers (1)

Answers (1)

sanjali07
Participant
0 Kudos

To get all values in a queue we have to use the Output parameter of the mapping function so it would look something like this,

import com.sap.it.api.mapping.*;

def void GetListByToken(String[] input,String[] token, Output output) {
    def inputList = input[0].tokenize(token[0]);
    
    if(inputList){
        inputList.each{
            output.addValue(it);
        }
    }
}

Regards

Sanjali

anurag_sinha3
Participant
0 Kudos

thanks..

both solutions working