Groovy Examples

Go to list of examples

Filename MPL Custom Header Property

Filename MPL Custom Header Property

This script adds CamelFileName header as custom header property filename. Then you can see this extra metadata in MPL logs, and search the logs with filename.

It is useful for SFTP->Cloud Integration EDI scenarios.

Search with more than one identifier

Normally you can only add single identifier to search with SAP_ApplicationID. This feature enables storing several identifiers at the same time like IDoc number, PO number, etc. and searching them.

Since 2021 January, this field is included in the standard monitoring fields, so it should be indexed and fine to use.

SAP Community Blog for explaining the feature https://blogs.sap.com/2020/09/13/sap-cpi-a-guide-to-mpl-search/

Script

Try it on Groovy IDE
import com.sap.gateway.ip.core.customdev.util.Message;

def Message processData(Message message) {
    
	def messageLog = messageLogFactory.getMessageLog(message);
	if(messageLog != null){

		def filename = message.getHeaders().get("CamelFileName");		
		if(filename!=null){
			messageLog.addCustomHeaderProperty("filename", filename);		
        }
	}
	return message;
}

Input Headers

Key Value
CamelFileName filenameabc.txt