on ‎2023 Feb 10 5:49 AM
Hi guys,
I am writing the below code to split the string(separated by comma) into a list array.
I am giving multiple values to "source value" in content modifier.
Code:
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.util.regex.*;
import groovy.xml.*;
def Message processData(Message message) {
def headers = message.getHeaders();
def rows;
def properties = message.getProperties();
def credentials = properties.get("UserList");
List<String> myList = Arrays.asList(credentials.split(","));
for(i=0;i < myList.size();i++)
{
rows = rows + (myList[i]+"\n");
}
// rows = rows.replace("null","");
message.setBody(rows)
return message;
}
But when I run this, I was able to get the below output.
Output:myoutput.png
I am getting a null at the beginning, I can simply replace it. I also tries to assign null value to my variable"rows". But still I am getting the same output. I want to know what is wrong with my groovy code.
Thank you!
Request clarification before answering.
Dear Veena,
This issue can be fixed by various ways. I would say just define rows as "" while initializing.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.util.regex.*;
import groovy.xml.*;
def Message processData(Message message) {
def headers = message.getHeaders();
def rows = "";
def properties = message.getProperties();
def credentials = properties.get("UserList");
List<String> myList = Arrays.asList(credentials.split(","));
for(i=0;i < myList.size();i++)
{
rows = rows + (myList[i]+"\n");
}
// rows = rows.replace("null","");
message.setBody(rows)
return message;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Veena,
Since you already created List, you can check and remove null values first, then continue with your logic.
list.removeAll([null])
Best regards,
Akmal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 9 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.