<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: SAP CPI - Groovy script to split a string and make an array list in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/sap-cpi-groovy-script-to-split-a-string-and-make-an-array-list/qaa-p/12654641#M4747488</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Yes. It worked. I should define "" to my variable. It is just my mistake! &lt;/P&gt;&lt;P&gt;Thank you so much.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Veena&lt;/P&gt;</description>
    <pubDate>Mon, 06 Mar 2023 14:33:49 GMT</pubDate>
    <dc:creator>veenagayathri</dc:creator>
    <dc:date>2023-03-06T14:33:49Z</dc:date>
    <item>
      <title>SAP CPI - Groovy script to split a string and make an array list</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cpi-groovy-script-to-split-a-string-and-make-an-array-list/qaq-p/12654638</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;
  &lt;P&gt;I am writing the below code to split the string(separated by comma) into a list array.&lt;/P&gt;
  &lt;P&gt;I am giving multiple values to "source value" in content modifier.&lt;/P&gt;
  &lt;P&gt;&lt;A href="https://answers.sap.com/storage/temp/2140512-mycontentmodifier.png" data-attachment="2140512"&gt;mycontentmodifier.png&lt;/A&gt;&lt;/P&gt;
  &lt;P&gt;Code:&lt;/P&gt;
  &lt;P&gt;import com.sap.gateway.ip.core.customdev.util.Message;&lt;/P&gt;
  &lt;P&gt;import java.util.HashMap;&lt;/P&gt;
  &lt;P&gt;import java.util.regex.*;&lt;/P&gt;
  &lt;P&gt;import groovy.xml.*;&lt;/P&gt;
  &lt;P&gt;def Message processData(Message message) {&lt;/P&gt;
  &lt;P&gt; def headers = message.getHeaders();&lt;/P&gt;
  &lt;P&gt; def rows;&lt;/P&gt;
  &lt;P&gt; def properties = message.getProperties();&lt;/P&gt;
  &lt;P&gt; def credentials = properties.get("UserList");&lt;/P&gt;
  &lt;P&gt; List&amp;lt;String&amp;gt; myList = Arrays.asList(credentials.split(","));&lt;/P&gt;
  &lt;P&gt; for(i=0;i &amp;lt; myList.size();i++)&lt;/P&gt;
  &lt;P&gt; {&lt;/P&gt;
  &lt;P&gt; rows = rows + (myList[i]+"\n");&lt;/P&gt;
  &lt;P&gt; }&lt;/P&gt;
  &lt;P&gt; // rows = rows.replace("null","");&lt;/P&gt;
  &lt;P&gt; message.setBody(rows)&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; return message;&lt;/P&gt;
  &lt;P&gt;}&lt;/P&gt;
  &lt;P&gt;But when I run this, I was able to get the below output.&lt;/P&gt;
  &lt;P&gt;Output:&lt;A href="https://answers.sap.com/storage/temp/2140517-myoutput.png" data-attachment="2140517"&gt;myoutput.png&lt;/A&gt;&lt;/P&gt;
  &lt;P&gt;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.&lt;/P&gt;
  &lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 05:49:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cpi-groovy-script-to-split-a-string-and-make-an-array-list/qaq-p/12654638</guid>
      <dc:creator>veenagayathri</dc:creator>
      <dc:date>2023-02-10T05:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAP CPI - Groovy script to split a string and make an array list</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cpi-groovy-script-to-split-a-string-and-make-an-array-list/qaa-p/12654639#M4747486</link>
      <description>&lt;P&gt;Hello Veena,&lt;/P&gt;&lt;P&gt;Since you already created List, you can check and remove null values first, then continue with your logic.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;list.removeAll([null])&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Akmal&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 06:40:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cpi-groovy-script-to-split-a-string-and-make-an-array-list/qaa-p/12654639#M4747486</guid>
      <dc:creator>akmal1216</dc:creator>
      <dc:date>2023-02-10T06:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAP CPI - Groovy script to split a string and make an array list</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cpi-groovy-script-to-split-a-string-and-make-an-array-list/qaa-p/12654640#M4747487</link>
      <description>&lt;P&gt;Dear Veena,&lt;/P&gt;&lt;P&gt;This issue can be fixed by various ways. I would say just define rows as "" while initializing.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;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&amp;lt;String&amp;gt; myList = Arrays.asList(credentials.split(","));

for(i=0;i &amp;lt; myList.size();i++)

{

rows = rows + (myList[i]+"\n");

}

// rows = rows.replace("null","");

message.setBody(rows)

return message;

}&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Feb 2023 14:07:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cpi-groovy-script-to-split-a-string-and-make-an-array-list/qaa-p/12654640#M4747487</guid>
      <dc:creator>asutoshmaharana2326</dc:creator>
      <dc:date>2023-02-10T14:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: SAP CPI - Groovy script to split a string and make an array list</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cpi-groovy-script-to-split-a-string-and-make-an-array-list/qaa-p/12654641#M4747488</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Yes. It worked. I should define "" to my variable. It is just my mistake! &lt;/P&gt;&lt;P&gt;Thank you so much.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Veena&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2023 14:33:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cpi-groovy-script-to-split-a-string-and-make-an-array-list/qaa-p/12654641#M4747488</guid>
      <dc:creator>veenagayathri</dc:creator>
      <dc:date>2023-03-06T14:33:49Z</dc:date>
    </item>
  </channel>
</rss>

