cancel
Showing results for 
Search instead for 
Did you mean: 

Trace Messages in Groovy script - SAP CPI - Is it possible ?

arnab_mondal2
Participant
0 Kudos

Hi Experts ,

In SAP PI /PO we have the option of finding the status of the data within UDF using trace messages . Something like this . This helps to understand the status of the data at different stages of the UDF. Do we have anything compatible for CPI - Groovy ?

Accepted Solutions (1)

Accepted Solutions (1)

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Arnab,

Above option is not available in Simulate option of Message Mapping since we dont have any explicit option to set the trace level.

Regards,

Sriprasad Shivaram Bhat

arnab_mondal2
Participant
0 Kudos

This is exactly what I was trying to know 🙂 Thanks Sriprasad !

Answers (4)

Answers (4)

philippeaddor
Active Participant
0 Kudos
former_member194481
Participant
0 Kudos

Hi Arnab,

Currently groovy scripts support the field and payload based, but the UDF in mapping doesnt support. As an alternative, if you want to know the value of certain field then create header with Xpath in content modifier then read it in the Groovy Script that will be visible in the MPL.

    def headers= displayMaps("##Headers:", message.getHeaders())
    def properties = displayMaps("##Properties:", message.getProperties())

def messageLog = messageLogFactory.getMessageLog(message);
messageLog.setStringProperty("NametoSeeInMPL", value)

Thanks and Regards,
Vijay.
arnab_mondal2
Participant
0 Kudos

No , this is not what I am looking for . I wish to set up a debugger at the groovy script level itself . The above are payload based , what I am looking at is field based !

christian102094
Participant
0 Kudos

Hello,

You can configure it in the Monitoring view:

Also, you could save the Message content as attachments of the process (not good performance, so use it only in dev/test):

def Message saveMessageContent(Message message) {
	def displayMaps = { String mapName, Map map ->
		StringBuilder sb = new StringBuilder()
		sb.append(mapName).append("\n")
		map.each { key, value -> sb.append(key).append(" = ").append(value).append("\n")  }
		return sb.toString()
	}
	
    def headers = displayMaps("##Headers:", message.getHeaders())
    def properties = displayMaps("##Properties:", message.getProperties())
    
    def body = message.getBody() as String; // java.lang.String
    
    def messageLog = messageLogFactory.getMessageLog(message);
    if(messageLog != null){
        messageLog.addAttachmentAsString("MessageBody", body, "text/plain");
        messageLog.addAttachmentAsString("MessageHeaders", headers, "text/plain");
        messageLog.addAttachmentAsString("MessageProperties", properties, "text/plain");
     }
    return message;
}

Best regards.