<?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: Converting String To Integer in sap cpi in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/converting-string-to-integer-in-sap-cpi/qaa-p/12528446#M4696355</link>
    <description>&lt;P&gt;Hi Vineetha, &lt;/P&gt;&lt;P&gt;Modify the below code as per your requirement.&lt;/P&gt;&lt;P&gt;try{&lt;/P&gt;&lt;P&gt;    if (val.isInteger() == true)&lt;/P&gt;&lt;P&gt;    {&lt;/P&gt;&lt;P&gt;        def modifedVal = val.toInteger()&lt;/P&gt;&lt;P&gt;    }&lt;/P&gt;&lt;P&gt;    }&lt;/P&gt;&lt;P&gt;    catch(Exception ex) {&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt;      }&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt;Here val is the field name. &lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Priyanka&lt;/P&gt;</description>
    <pubDate>Thu, 21 Apr 2022 08:35:02 GMT</pubDate>
    <dc:creator>PriyankaChak</dc:creator>
    <dc:date>2022-04-21T08:35:02Z</dc:date>
    <item>
      <title>Converting String To Integer in sap cpi</title>
      <link>https://community.sap.com/t5/technology-q-a/converting-string-to-integer-in-sap-cpi/qaq-p/12528444</link>
      <description>&lt;P&gt;Hi EveryOne,&lt;/P&gt;
  &lt;P&gt;I have a requirement to convert the string data type to integer data type if the field has an integer number, else if the field has a string value pass it as it is.&lt;/P&gt;
  &lt;P&gt;for example, I have the payload&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2042466-image.png" /&gt;&lt;/P&gt;
  &lt;P&gt;for the field "PurReqnSSPCatalogForEdit" I have an integer value. I need to convert it from string to integer.&lt;/P&gt;
  &lt;P&gt;I have written the below groovy script for this&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 groovy.json.*&lt;/P&gt;
  &lt;P&gt;def Message processData(Message message) {&lt;/P&gt;
  &lt;P&gt; //Body &lt;/P&gt;
  &lt;P&gt; def jsonOP = message.getBody(String.class);&lt;/P&gt;
  &lt;P&gt; jsonOP=jsonOP.toString()&lt;/P&gt;
  &lt;P&gt; def json_to_str="{\"Element\":["+jsonOP+"]}"&lt;/P&gt;
  &lt;P&gt; def jsonSlurper = new JsonSlurper();&lt;/P&gt;
  &lt;P&gt; def list = jsonSlurper.parseText(json_to_str);&lt;/P&gt;
  &lt;P&gt; list.Element.each{ &lt;/P&gt;
  &lt;P&gt; it.EmployeeForEdit.toString()&lt;/P&gt;
  &lt;P&gt; it.BusinessObjectTypeForEdit.toString()&lt;/P&gt;
  &lt;P&gt; it.PurReqnSSPCatalogForEdit=Integer.parseInt(it.get("PurReqnSSPCatalogForEdit").toString());&lt;/P&gt;
  &lt;P&gt; }&lt;/P&gt;
  &lt;P&gt; def jsonlist = JsonOutput.toJson(list);&lt;/P&gt;
  &lt;P&gt; def jsonObject = jsonSlurper.parseText(jsonlist);&lt;/P&gt;
  &lt;P&gt; def removerootnode = JsonOutput.toJson(jsonObject["Element"]);&lt;/P&gt;
  &lt;P&gt; def removebraket = removerootnode.replace("[","");&lt;/P&gt;
  &lt;P&gt; def removeendbraket = removebraket.replace("]","");&lt;/P&gt;
  &lt;P&gt; message.setBody(removeendbraket);&lt;/P&gt;
  &lt;P&gt; return message;&lt;/P&gt;
  &lt;P&gt;}&lt;/P&gt;
  &lt;P&gt;But if the field "PurReqnSSPCatalogForEdit" has a string value parse it as it is. What is the condition I need to add to the above groovy script to achieve this? Please provide a solution for it&lt;/P&gt;
  &lt;P&gt;Thank You,&lt;/P&gt;
  &lt;P&gt;Vineetha.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 08:07:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/converting-string-to-integer-in-sap-cpi/qaq-p/12528444</guid>
      <dc:creator>vineetha12</dc:creator>
      <dc:date>2022-04-21T08:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: Converting String To Integer in sap cpi</title>
      <link>https://community.sap.com/t5/technology-q-a/converting-string-to-integer-in-sap-cpi/qaa-p/12528445#M4696354</link>
      <description>&lt;P&gt;Hello Vineetha,&lt;/P&gt;&lt;P&gt;Pleaes refer below KBA.&lt;/P&gt;&lt;P&gt;&lt;A href="https://userapps.support.sap.com/sap/support/knowledge/en/2521044" target="_blank"&gt;https://userapps.support.sap.com/sap/support/knowledge/en/2521044&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://answers.sap.com/questions/168650/sap-hci-xml-to-json-converter-string-to-integer.html" target="_blank"&gt;https://answers.sap.com/questions/168650/sap-hci-xml-to-json-converter-string-to-integer.html&lt;/A&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Regards&lt;/STRONG&gt;,&lt;/P&gt;&lt;P&gt;Sriprasad Shivaram Bhat&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 08:29:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/converting-string-to-integer-in-sap-cpi/qaa-p/12528445#M4696354</guid>
      <dc:creator>Sriprasadsbhat</dc:creator>
      <dc:date>2022-04-21T08:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: Converting String To Integer in sap cpi</title>
      <link>https://community.sap.com/t5/technology-q-a/converting-string-to-integer-in-sap-cpi/qaa-p/12528446#M4696355</link>
      <description>&lt;P&gt;Hi Vineetha, &lt;/P&gt;&lt;P&gt;Modify the below code as per your requirement.&lt;/P&gt;&lt;P&gt;try{&lt;/P&gt;&lt;P&gt;    if (val.isInteger() == true)&lt;/P&gt;&lt;P&gt;    {&lt;/P&gt;&lt;P&gt;        def modifedVal = val.toInteger()&lt;/P&gt;&lt;P&gt;    }&lt;/P&gt;&lt;P&gt;    }&lt;/P&gt;&lt;P&gt;    catch(Exception ex) {&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt;      }&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt;Here val is the field name. &lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Priyanka&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 08:35:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/converting-string-to-integer-in-sap-cpi/qaa-p/12528446#M4696355</guid>
      <dc:creator>PriyankaChak</dc:creator>
      <dc:date>2022-04-21T08:35:02Z</dc:date>
    </item>
  </channel>
</rss>

