import com.sap.gateway.ip.core.customdev.util.Message import groovy.xml.XmlSlurper import groovy.xml.StreamingMarkupBuilder
def Message processData(Message message) { // Read message log to log the original payload def messageLog = messageLogFactory.getMessageLog(message)
// Read the incoming XML body as a String
String body = message.getBody(java.lang.String)
// Log the original payload before any transformation
if (messageLog != null) {
messageLog.addAttachmentAsString("OriginalPayload", body, "text/xml")
}
// Parse the XML using XmlSlurper (namespace-aware)
def order = new XmlSlurper().parseText(body)
// Transform productName to upper case - field exists in allowedFieldNames
def currentProductName = order.productName.text()
order.productName.replaceBody(currentProductName.toUpperCase())
// Serialize the modified XML back to a String, preserving structure/namespaces
String updatedXml = new StreamingMarkupBuilder().bindNode(order).toString()
// Set the updated XML as the new message body
message.setBody(updatedXml)
return message
}