Skip to Content
Technical Articles
Author's profile photo naveen kumar171

Groovy script to print comments/texts in the attachment in SAP CPI

Hi All,

 

I have searched a lot about how to print the comments using Groovy script (for reference whether the flow is executing or not without storing the payload) in CPI. But I couldn’t find any blogs, so I’m posting this.

 

Here using Groovy script, I am printing the comments/texts (whatever we want) in the attachment of SAP CPI environment. Just to check whether the flow has been completed or not.

<comments is the variable declared to get the value to be displayed>

Use the below script in Groovy Script

import com.sap.gateway.ip.core.customdev.util.Message;
def Message processData(Message message)
{
def comments=”Hello Groovy script”;
def messageLog = messageLogFactory.getMessageLog(message);
messageLog.addAttachmentAsString(“ResponsePayload:”, comments, “text/plain”);
return message;
}

Once deployed, in Monitoring — go to Attachment, then you will see the logs and the commesnts will be displayed like below in the log.

 

Thanks,

Naveen

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Harika Kaviti
      Harika Kaviti

      Hi

       

      If the attachment is empty and nothing to be sent, then can you help me in that case to write a script?