on 09-22-2023 1:06 PM
import com.sap.gateway.ip.core.customdev.util.Message
import java.util.Map
import java.util.Iterator
import javax.activation.DataHandler
def Message processData(Message message) {
def attachments = message.getAttachments();
def bTypeSupported = false;
if ((attachments!=null)&&(!attachments.isEmpty())) {
attachments.values().each{ attachment ->
if (bTypeSupported == true){
return;
}
def sContentType = attachment.getContentType()
message.setProperty("MailContentType", sContentType);
sContentType = sContentType.substring(0, sContentType.lastIndexOf(";")).toLowerCase();
if (sContentType.contains("csv")){
sContentType="text/csv";
bTypeSupported = true;
}
if (bTypeSupported == true){
message.setProperty("MailContentTypeSupported", "True");
message.setBody(attachment.getContent());
message.setHeader("attachment_fileName",attachment.getName());
message.setHeader("attachment_type",sContentType);
}
}
}
return message
}
another problem is you cannot keep tracing enabled for longer duration and once again another pathetically designed adapter for handling things like attachment for which we have to take help from groovy script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello AR,
you can introduce some error handling and retries in your script, retry the below logic,
import com.sap.gateway.ip.core.customdev.util.Message def MAX_RETRIES = 3 def Message processData(Message message) { def retryCount = 0 while (retryCount < MAX_RETRIES) { try { processAttachments(message) return message } catch (Exception e) { retryCount++ if (retryCount < MAX_RETRIES) { log.error("Error processing attachments. Retrying (Attempt $retryCount)") } else { log.error("Max retries reached. Unable to process attachments.") throw e } } } return message } def processAttachments(Message message) { def attachments = message.getAttachments() def bTypeSupported = false if (attachments != null && !attachments.isEmpty()) { attachments.values().each { attachment -> if (bTypeSupported) { return } def sContentType = attachment.getContentType() message.setProperty("MailContentType", sContentType) sContentType = sContentType.substring(0, sContentType.lastIndexOf(";")).toLowerCase() if (sContentType.contains("csv")) { sContentType = "text/csv" bTypeSupported = true } if (bTypeSupported) { message.setProperty("MailContentTypeSupported", "True") message.setBody(attachment.getContent()) message.setHeader("attachment_fileName", attachment.getName()) message.setHeader("attachment_type", sContentType) } } } }
a MAX_RETRIES constant to specify the maximum number of retry attempts.
The processData function now includes a retry loop that attempts to process attachments. If an exception is caught, it will retry up to the maximum number of times defined by MAX_RETRIES. The processAttachments function remains mostly the same for processing attachments. This retry logic should help address the issue of attachments not being fully loaded or available on the first attempt. If there's an error during processing, the script will log the error and retry until the maximum number of retries is reached or the processing is successful.
Alternately you can check the below blog for configuring mail sender Adapter in Integration suite.
https://blogs.sap.com/2023/02/26/inbound-email-integration-from-o365-to-sap-s4-via-sap-cpi/
Thanks,
Lakshmi.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
9 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.