<?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 Cloud Platform Integration: Call Groovy Script with parameters in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/572880#M128200</link>
    <description>&lt;P&gt;Hey Morten,&lt;/P&gt;
  &lt;P&gt;thank you very much. With the void function it didn't worked for me. So thats the code how it works for me.&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;import com.sap.gateway.ip.core.customdev.util.Message
import java.util.HashMap
def Message logInitialFlatFile(Message message) {
   message = logPayload(message, "initialFlatFile.txt", "text/plain")
}

def Message logInitialXml(Message message) {
   message = logPayload(message, "initialXML.xml", "application/xml")
}

def Message logPayload(Message message, String nameOfAttachment, String mimeType ) {
    def payload = message.getBody(String.class);
    def messageLog = messageLogFactory.getMessageLog(message)        
    messageLog.setStringProperty("Logging", nameOfAttachment)        
    messageLog.addAttachmentAsString(nameOfAttachment, payload, mimeType)
    return message
}&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 11 Dec 2017 14:15:10 GMT</pubDate>
    <dc:creator>Florian_Kube</dc:creator>
    <dc:date>2017-12-11T14:15:10Z</dc:date>
    <item>
      <title>SAP Cloud Platform Integration: Call Groovy Script with parameters</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaq-p/572878</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
  &lt;P&gt;I am using groovy scripts for logging in different steps. Since I do not want to copy the scripts repeatedly and change just two values, I thought there should be the possibility to use parameters.&lt;/P&gt;
  &lt;P&gt;Here is the script I want to use:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message logpayload(Message message, String nameOfAttachment, String mimeType ) {
    def payload = message.getBody(String.class);                            
    def messageLog = messageLogFactory.getMessageLog(message);
    messageLog.setStringProperty("Logging", nameOfAttachment);
    messageLog.addAttachmentAsString(nameOfAttachment, payload, mimeType);
    return message;
}
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;I configurate it like this:&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/98359-2017-12-11-08-40-30-sap-cloud-platform-integration.png" /&gt;&lt;/P&gt;
  &lt;P&gt;However, when I run it I get the following exception. Does anyone have an Idea how I could solve this issue?&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;
java.lang.NoSuchMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.logpayload(message, "FlatFile.txt", "text/plain")() is applicable for argument types: (com.sap.gateway.ip.core.customdev.processor.MessageImpl) values: [com.sap.gateway.ip.core.customdev.processor.MessageImpl@737f25ed]
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Thank you,&lt;/P&gt;
  &lt;P&gt;Florian&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 07:43:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaq-p/572878</guid>
      <dc:creator>Florian_Kube</dc:creator>
      <dc:date>2017-12-11T07:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAP Cloud Platform Integration: Call Groovy Script with parameters</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/572879#M128199</link>
      <description>&lt;P&gt;Hi Florian&lt;/P&gt;
  &lt;P&gt;CPI expects the signature of your Script step function to be:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;Message functionName(Message message)&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;You can, however, add as many functions with arbitrary signatures to your script file, as you need.&lt;/P&gt;
  &lt;P&gt;You could, therefore, change your logPayload method to be: &lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;def void logPayload(Message message, String nameOfAttachment, String mimeType) &lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;and then add any number of functions calling it, like:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;def Message logInitialXml(Message message) {
   logPayload(message, 'initialXML.xml', 'application/xml')
   message // In Groovy, this is equivalent to return message
}&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;That would remove the duplicated code.&lt;/P&gt;
  &lt;P&gt;Let me know how it works out.&lt;/P&gt;
  &lt;P&gt;Regards,&lt;/P&gt;
  &lt;P&gt;Morten&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 12:07:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/572879#M128199</guid>
      <dc:creator>MortenWittrock</dc:creator>
      <dc:date>2017-12-11T12:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAP Cloud Platform Integration: Call Groovy Script with parameters</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/572880#M128200</link>
      <description>&lt;P&gt;Hey Morten,&lt;/P&gt;
  &lt;P&gt;thank you very much. With the void function it didn't worked for me. So thats the code how it works for me.&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;import com.sap.gateway.ip.core.customdev.util.Message
import java.util.HashMap
def Message logInitialFlatFile(Message message) {
   message = logPayload(message, "initialFlatFile.txt", "text/plain")
}

def Message logInitialXml(Message message) {
   message = logPayload(message, "initialXML.xml", "application/xml")
}

def Message logPayload(Message message, String nameOfAttachment, String mimeType ) {
    def payload = message.getBody(String.class);
    def messageLog = messageLogFactory.getMessageLog(message)        
    messageLog.setStringProperty("Logging", nameOfAttachment)        
    messageLog.addAttachmentAsString(nameOfAttachment, payload, mimeType)
    return message
}&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Dec 2017 14:15:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/572880#M128200</guid>
      <dc:creator>Florian_Kube</dc:creator>
      <dc:date>2017-12-11T14:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAP Cloud Platform Integration: Call Groovy Script with parameters</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/572881#M128201</link>
      <description>&lt;P&gt;Hi Florian. Glad you could use it. As for void, use&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;def logPayload(Message message, String nameOfAttachment, String mimeType )&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;instead, and it should work. That requires changing the code as for the return statements.&lt;/P&gt;
  &lt;P&gt;Or you can leave it as it is now, if you prefer.&lt;/P&gt;
  &lt;P&gt;Regards,&lt;/P&gt;
  &lt;P&gt;Morten&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 14:21:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/572881#M128201</guid>
      <dc:creator>MortenWittrock</dc:creator>
      <dc:date>2017-12-11T14:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAP Cloud Platform Integration: Call Groovy Script with parameters</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/572882#M128202</link>
      <description>&lt;P&gt;Hi Florian,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;another solution would be to use properties or header variables. You can than access them with &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;map = message.getHeaders();
myVar = map.get("variableName");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;map = message.getProperties();
myVar = map.get("variableName");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can be another solution that might be more flexibility but adds more cpi specific code.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Dominic&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 16:35:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/572882#M128202</guid>
      <dc:creator>dominic4</dc:creator>
      <dc:date>2018-10-23T16:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAP Cloud Platform Integration: Call Groovy Script with parameters</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/572883#M128203</link>
      <description>&lt;P&gt;Thanks to Morten for this solution, just to complete this answer for the benefit of other readers trying to figure out how to use the 'Script Function' feature, when configuring the Script Function name under 'Processing' tab, mention only the script name (no need of parenthesis or passing the 'message' parameter, this is implicitly understood by CPI that only a 'message' parameter can be passed through the Script Function), screenshots below showing the incorrect and correct approach (had to figure this out with few trial and errors as I couldn't find any documentations with examples of using this feature).&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Wrong &lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1783475-wrong.jpg" /&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Correct &lt;/STRONG&gt;: &lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1783476-correct.jpg" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2020 05:35:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/572883#M128203</guid>
      <dc:creator>bharathsai_r</dc:creator>
      <dc:date>2020-02-13T05:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: SAP Cloud Platform Integration: Call Groovy Script with parameters</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/572884#M128204</link>
      <description>&lt;P&gt;This.&lt;/P&gt;&lt;P&gt;So, to surmise, user defined functions in Groovy scripts for CPI iFlows:&lt;/P&gt;&lt;P&gt;1. Must have only one argument and that's message  - hence we only need to specify the Script Function name like Bharath has shown in the 'correct' screenshot.&lt;/P&gt;&lt;P&gt;2. processData - which appears by default when we create a groovy script, is not mandatory to be implemented.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;7a519509aed84a2c9e6f627841825b5a&lt;/SPAN&gt; - please comment if these assumptions are right? &lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2020 11:47:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/572884#M128204</guid>
      <dc:creator>KeshavDesai</dc:creator>
      <dc:date>2020-02-14T11:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: SAP Cloud Platform Integration: Call Groovy Script with parameters</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/572885#M128205</link>
      <description>&lt;P&gt;The post of Dominic is the one!&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Matthias&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 18:13:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/572885#M128205</guid>
      <dc:creator>MatthiasFricke</dc:creator>
      <dc:date>2020-03-04T18:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAP Cloud Platform Integration: Call Groovy Script with parameters</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/13922875#M4890387</link>
      <description>Hi Florian, were you able to invoke a method in Class A from another groovy script, where Class A is loaded as a Master Script under global references to the Iflow ?</description>
      <pubDate>Tue, 29 Oct 2024 17:13:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-cloud-platform-integration-call-groovy-script-with-parameters/qaa-p/13922875#M4890387</guid>
      <dc:creator>RaviRIyer</dc:creator>
      <dc:date>2024-10-29T17:13:55Z</dc:date>
    </item>
  </channel>
</rss>

