Groovy scripting is the primary way to add custom logic to integration flows in SAP Integration Suite (formerly SAP CPI). When standard components — Content Modifier, Message Mapping, Router — can’t express the business logic you need, a Groovy script steps in. With it you can transform payloads, read and write headers and exchange properties, handle exceptions, call external APIs, log custom trace data, and control iFlow execution at runtime.
This guide covers Groovy fundamentals for SAP Integration Suite developers: what Groovy is, how to add it to an iFlow, the most common use cases with code examples, and practical tips from our integration consultants.
Table of Contents
Groovy is a dynamic, JVM-based scripting language that combines the power of Java with a concise, readable syntax. In SAP Integration Suite, Groovy scripts run inside the Script step of an integration flow and receive the SAP Message object — giving full programmatic access to the payload, headers, and exchange properties of the message being processed.
Message
Key features that make Groovy ideal for SAP CPI scripting:
def
com.sap.gateway.ip.core.customdev.util.Message
.groovy
processData(Message message)
Tip: Use groovyide.com/cpi to test and validate Groovy scripts against a CPI-compatible sandbox before deploying to your tenant. This eliminates the slow deploy-run-check cycle during development.
Every Groovy script in SAP Integration Suite must implement the processData method. This is the entry point called by the integration runtime when the Script step executes:
processData
import com.sap.gateway.ip.core.customdev.util.Message import java.util.HashMap def Message processData(Message message) { // Your custom logic here return message }
The method receives the current Message object and must return it (modified or unchanged) after processing. The integration flow proceeds with the returned message.
def Message processData(Message message) { def body = message.getBody(java.lang.String) as String // Modify the body string as needed def modifiedBody = body.replace('OldValue', 'NewValue') message.setBody(modifiedBody) return message }
def Message processData(Message message) { def headers = message.getHeaders() def contentType = headers.get('Content-Type') // Set a new header message.setHeader('X-Custom-Header', 'MyValue') return message }
def Message processData(Message message) { def properties = message.getProperties() def orderNumber = properties.get('OrderNumber') // Write a new property for use in downstream steps message.setProperty('ProcessedOrderNumber', orderNumber + '-PROCESSED') return message }
By default, message payloads are only visible in trace mode. Use the message log API to capture custom data at any log level:
import com.sap.gateway.ip.core.customdev.util.Message import java.util.HashMap def Message processData(Message message) { def body = message.getBody(java.lang.String) as String def messageLog = messageLogFactory.getMessageLog(message) if (messageLog != null) { messageLog.addAttachmentAsString('Payload Snapshot', body, 'text/plain') } return message }
This is especially useful for debugging production issues without enabling full trace mode on the iFlow.
import com.sap.gateway.ip.core.customdev.util.Message def Message processData(Message message) { def xmlPayload = new XmlSlurper().parseText(message.getBody(java.lang.String) as String) def orderID = xmlPayload.OrderID.text() message.setProperty('OrderID', orderID) return message }
import com.sap.gateway.ip.core.customdev.util.Message import groovy.json.JsonSlurper def Message processData(Message message) { def json = new JsonSlurper().parseText(message.getBody(java.lang.String) as String) def customerId = json.customer.id message.setProperty('CustomerID', customerId.toString()) return message }
import com.sap.gateway.ip.core.customdev.util.Message def Message processData(Message message) { def status = message.getProperty('ResponseStatus') if (status != '200') { throw new Exception("Upstream system returned error status: ${status}") } return message }
The thrown exception triggers any Exception Subprocess configured in the iFlow, allowing structured error handling and alerting.
import com.sap.gateway.ip.core.customdev.util.Message import com.sap.it.api.exception.IgnoreMessageException def Message processData(Message message) { def flag = message.getProperty('SkipProcessing') if (flag == 'true') { throw new IgnoreMessageException() } return message }
The IgnoreMessageException terminates the iFlow cleanly with a Completed status and no error, useful for conditional processing logic.
IgnoreMessageException
Completed
SAP Integration Suite supports both Groovy and JavaScript as scripting languages. For most integration developers, Groovy is the preferred choice because:
XmlSlurper
JsonSlurper
JavaScript remains useful if your team has strong JS expertise or if you’re doing light string manipulation that doesn’t require Java library access.
ITApiFactory
PROCESSING_FAILED
The required entry point is def Message processData(Message message). The SAP integration runtime calls this method when the Script step executes. The method must return the Message object after any modifications. Additional helper methods can be defined in the same script but are called from processData.
def Message processData(Message message)
Use message.getProperties() to retrieve a map of all exchange properties, then access individual values with .get('PropertyName'). To set a property: message.setProperty('PropertyName', value). Headers are accessed with message.getHeaders() and set with message.setHeader('HeaderName', value).
message.getProperties()
.get('PropertyName')
message.setProperty('PropertyName', value)
message.getHeaders()
message.setHeader('HeaderName', value)
Yes. Standard Java libraries available on the Integration Suite runtime (Java SE classes, SAP-provided APIs) can be imported with standard import statements. You cannot add arbitrary third-party JAR files; only libraries bundled with the Integration Suite runtime are available.
import
In message mapping (Graphical Mapping), Groovy is used to write custom User-Defined Functions (UDFs) that transform individual field values during mapping. In a Script step, Groovy operates on the entire message object — payload, headers, and properties — outside of mapping. Script steps are more powerful but also more complex; use them for logic that cannot be expressed in standard mapping functions.
Three approaches: (1) Enable Trace level logging on the iFlow during development and inspect message processing steps in the Monitor. (2) Use the messageLogFactory API to attach custom snapshots to the message log at any log level without requiring trace mode. (3) Use an external Groovy IDE (groovyide.com/cpi or IntelliJ IDEA with the CPI stubs) to test script logic locally before deploying.
messageLogFactory
SAP PI/PO & SAP Integration Suite (CPI) Consultant Enes Varinli is an integration consultant who works on the analysis, design, and implementation of end-to-end ERP integrations between SAP and non-SAP systems and third-party applications. He focuses on developing sustainable and scalable integration architectures that are centered on business processes.
Generative AI in Warehousing
In today's rapidly evolving landscape of warehouse management, the integration of cutting-edge technologies is inevitable for staying...
Using SAP EWM with RFUI for Efficient Warehouse Management
Overview of SAP EWM with RFUISAP EWM with RFUI is an advanced solution designed to manage complex and large-scale warehouse operations across various...
AI-Enhanced Knowledge Management System
In today’s era of digitalization, businesses generate and store vast amounts of data. This data is critical for informed decision-making and...
RFID Integration with SAP EWM
If you're a warehouse manager or supply chain professional, you know that managing a warehouse can be a complex and time-consuming task. From...
What is Agile Project Management?
There are many project management methodologies that project managers can choose from to best run projects. One of these methodologies is Agile...
Migrating from SAP WM to Embedded EWM: Step-by-Step Migration Guide
Migrating from SAP WM to Embedded EWM is not merely a technical system upgrade; it is a strategic migration project that requires the redesign of...
The Bridge Between DATEV and Zalando
We would like to introduce you to our new project!Known to us all for quality, fashion and creativity, Boyner Group serves over 15 million customers...
How to Integrate SAP with Azure?
Integrated systems have become critical in the corporate business world. In this article, we will get to know SAP and Azure, which are considered the...
How to Parameterize Decision Rules in SAP TM with BRF+
Introduction SAP Transportation Management (TM) handles complex logistics scenarios where countless decisions need to be made: Which sales orders...
Your mail has been sent successfully. You will be contacted as soon as possible.
Your message could not be delivered! Please try again later.