Wednesday, 8 October 2025

Prints the Message

 def messageLog = messageLogFactory.getMessageLog(message);

messageLog.addAttachmentAsString("Payload", message.getBody(String), "text/plain");


 message.getBody Logs the message body for debugging or monitoring purposes. 

 addAttachmentAsString("Payload" Attaches the payload as a string with a label (e.g., "Payload") in plain text format. 

 Helps trace message flow without modifying the actual message content.


Complete example – Fetch and Modify Data

import com.sap.gateway.ip.core.customdev.util.Message;

def Message processData(Message message) { 

    // Get Header and Property

    def sourceSystem = message.getHeader("SourceSystem")

    def docType = message.getProperty("DocumentType")

    // Get Body

    def body = message.getBody(String) 

    // Add new header

    message.setHeader("ProcessedBy", "GroovyScript")

     // Modify Body (append a note) 

    def newBody = body + "\n<!--Process by CPI-->"

    message.setBody(newBody)

     return message;

return message; }

No comments:

Post a Comment