Hello,
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.
Here is the script I want to use:
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;
}
I configurate it like this:

However, when I run it I get the following exception. Does anyone have an Idea how I could solve this issue?
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]
Thank you,
Florian
Request clarification before answering.
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).
Wrong :

Correct :

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This.
So, to surmise, user defined functions in Groovy scripts for CPI iFlows:
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.
2. processData - which appears by default when we create a groovy script, is not mandatory to be implemented.
7a519509aed84a2c9e6f627841825b5a - please comment if these assumptions are right?
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 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.