<?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: Groovy Script Parse Error in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/groovy-script-parse-error/qaa-p/13704877#M4829751</link>
    <description>&lt;a href="https://community.sap.com/t5/user/viewprofilepage/user-id/84254"&gt;@jbesl99&lt;/a&gt; best to post a new question outlining your new problem if you don't understand the issue or what to do next. There are quite a few folks on here that can assist you.</description>
    <pubDate>Fri, 17 May 2024 12:11:14 GMT</pubDate>
    <dc:creator>Ryan-Crosby</dc:creator>
    <dc:date>2024-05-17T12:11:14Z</dc:date>
    <item>
      <title>Groovy Script Parse Error</title>
      <link>https://community.sap.com/t5/technology-q-a/groovy-script-parse-error/qaq-p/13703850</link>
      <description>&lt;P&gt;Can you help me with a SAP CPI groovy script ?&lt;BR /&gt;Objective : I want to merge the content of an exchange property with XML content and the incoming payload by referencing a key &amp;lt;userId&amp;gt; in my case.&lt;/P&gt;&lt;P&gt;the sample format of the xml in the exchange property is this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;rootA&amp;gt;
	&amp;lt;cust_A_WFM&amp;gt;
		&amp;lt;cust_ADPWFMStatus&amp;gt;I&amp;lt;/cust_ADPWFMStatus&amp;gt;
		&amp;lt;externalCodeNav&amp;gt;
			&amp;lt;User&amp;gt;
				&amp;lt;userId&amp;gt;123456&amp;lt;/userId&amp;gt;
			&amp;lt;/User&amp;gt;
		&amp;lt;/externalCodeNav&amp;gt;
		&amp;lt;lastModifiedDateTime&amp;gt;*&amp;lt;/lastModifiedDateTime&amp;gt;
		&amp;lt;externalCode&amp;gt;*&amp;lt;/externalCode&amp;gt;
		&amp;lt;effectiveStartDate&amp;gt;*&amp;lt;/effectiveStartDate&amp;gt;
	&amp;lt;/cust_ADP_WFM&amp;gt;
	&amp;lt;cust_ADP_WFM&amp;gt;
		&amp;lt;cust_ADPWFMStatus&amp;gt;I&amp;lt;/cust_ADPWFMStatus&amp;gt;
		&amp;lt;externalCodeNav&amp;gt;
			&amp;lt;User&amp;gt;
				&amp;lt;userId&amp;gt;987654&amp;lt;/userId&amp;gt;
			&amp;lt;/User&amp;gt;
		&amp;lt;/externalCodeNav&amp;gt;
		&amp;lt;lastModifiedDateTime&amp;gt;*&amp;lt;/lastModifiedDateTime&amp;gt;
		&amp;lt;externalCode&amp;gt;*&amp;lt;/externalCode&amp;gt;
		&amp;lt;effectiveStartDate&amp;gt;2*&amp;lt;/effectiveStartDate&amp;gt;
	&amp;lt;/cust_A_WFM&amp;gt;
&amp;lt;/rootA&amp;gt;                        &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While the incoming payload, is this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using this script&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="json"&gt;import com.sap.gateway.ip.core.customdev.util.Message
import groovy.xml.XmlUtil
import groovy.xml.XmlParser

Message processData(Message message) {
    // Get the incoming payload
    def body = message.getBody(java.lang.String) as String

    // Get the exchange property containing cust_A_WFM
    def custADPWFMPayload = message.getProperty('backup_call1') as String

    // Remove the XML declaration if present
    body = body.replaceFirst(/\&amp;lt;\?xml.*?\?\&amp;gt;/, "").trim()
    custAWFMPayload = custAWFMPayload.replaceFirst(/\&amp;lt;\?xml.*?\?\&amp;gt;/, "").trim()

    // Parse both XMLs
    def parser = new XmlParser(false, false) // Disable namespace aware parsing
    def rootEmpJob = parser.parseText(body)
    def rootADP = parser.parseText(custAWFMPayload)

    // Convert the rootADP to a map for easy lookup
    def adpMap = rootADP.cust_A_WFM.collectEntries { adp -&amp;gt;
        [adp.externalCodeNav.User.userId.text(), adp]
    }

    // Iterate over each EmpJob element and merge, or remove if no match
    def empJobsToRemove = []
    rootEmpJob.EmpJob.each { empJob -&amp;gt;
        def userId = empJob.userId.text()
        def correspondingA = aMap[userId]
        if (correspondingA) {
            // Create a new node for externalCodeOfcust_A_WFMNav if it doesn't exist
            def userNav = empJob.userNav[0]
            if (userNav) {
                def externalCodeOfcust_A_WFMNav = userNav.externalCodeOfcust_A_WFMNav ?: userNav.appendNode('externalCodeOfcust_A_WFMNav')
                // Append the corresponding ADP data
                externalCodeOfcust_A_WFMNav.append(correspondingA)
            }
        } else {
            // Add to the list of nodes to remove
            empJobsToRemove &amp;lt;&amp;lt; empJob
        }
    }

    // Remove the unmatched EmpJob nodes
    empJobsToRemove.each { empJob -&amp;gt;
        rootEmpJob.remove(empJob)
    }

    // Convert the merged XML back to string and set it as the message body
    def mergedXml = XmlUtil.serialize(rootEmpJob)
    message.setBody(mergedXml)

    return message
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But i get this error&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
ADP_mergeXML_custADP_empData__Script.groovy: 3: unable to resolve class groovy.xml.XmlParser
@ line 3, column 1.
import groovy.xml.XmlParser
^

1 error
, cause: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
ADP_mergeXML_custADP_empData__Script.groovy: 3: unable to resolve class groovy.xml.XmlParser
@ line 3, column 1.
import groovy.xml.XmlParser
^

1 error&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 07:14:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/groovy-script-parse-error/qaq-p/13703850</guid>
      <dc:creator>jbesl99</dc:creator>
      <dc:date>2024-05-17T07:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: Groovy Script Parse Error</title>
      <link>https://community.sap.com/t5/technology-q-a/groovy-script-parse-error/qaa-p/13703858#M4829619</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Just remove this line:&amp;nbsp;&lt;/P&gt;&lt;P&gt;import groovy.xml.XmlParser&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;BR,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Andrzej&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 16:29:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/groovy-script-parse-error/qaa-p/13703858#M4829619</guid>
      <dc:creator>Andrzej_Filusz</dc:creator>
      <dc:date>2024-05-16T16:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: Groovy Script Parse Error</title>
      <link>https://community.sap.com/t5/technology-q-a/groovy-script-parse-error/qaa-p/13703864#M4829620</link>
      <description>&lt;P&gt;Change your import on line 3 to -&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import groovy.util.XmlParser&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ryan Crosby&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 16:34:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/groovy-script-parse-error/qaa-p/13703864#M4829620</guid>
      <dc:creator>Ryan-Crosby</dc:creator>
      <dc:date>2024-05-16T16:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: Groovy Script Parse Error</title>
      <link>https://community.sap.com/t5/technology-q-a/groovy-script-parse-error/qaa-p/13704406#M4829701</link>
      <description>Hello Ryan, this is my first time raising a question here, glad to have very quick response. Thank you it worked actually but i am getting a different error now</description>
      <pubDate>Fri, 17 May 2024 07:13:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/groovy-script-parse-error/qaa-p/13704406#M4829701</guid>
      <dc:creator>jbesl99</dc:creator>
      <dc:date>2024-05-17T07:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: Groovy Script Parse Error</title>
      <link>https://community.sap.com/t5/technology-q-a/groovy-script-parse-error/qaa-p/13704877#M4829751</link>
      <description>&lt;a href="https://community.sap.com/t5/user/viewprofilepage/user-id/84254"&gt;@jbesl99&lt;/a&gt; best to post a new question outlining your new problem if you don't understand the issue or what to do next. There are quite a few folks on here that can assist you.</description>
      <pubDate>Fri, 17 May 2024 12:11:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/groovy-script-parse-error/qaa-p/13704877#M4829751</guid>
      <dc:creator>Ryan-Crosby</dc:creator>
      <dc:date>2024-05-17T12:11:14Z</dc:date>
    </item>
  </channel>
</rss>

