Skip to Content
avatar image
Former Member

How to read SAP SRM PurchaseOrder Attachment in SAP PI on name

Hi Experts,

From SRM I'm receiving PurchaseOrders with multiple attachments in SAP PI. I have to put the attachments back into the PurchaseOrder on the correct orderlines as Base64.

In the PurchaseOrder orderline the name of the attachment is mentioned (the name also shown in SXMB_MONI, but this is not the attachment ID.(f.e. name: 4633755868859D58E100000083E00A10 but the attachment ID is: payload-4E33755868859D58E100000083E00A10@sap.com).

I'm using the java API https://help.sap.com/javadocs/PI/index.html?com/sap/aii/mapping/api/Attachment.html

Does anybody have a solution to retreive attachments based on Name instead of ID?

Here's mij codes:

String attachmentID = null;
AbstractTrace trace;
String base64content = "";
String fileType = "";
  //   try {
          GlobalContainer globalContainer = container.getGlobalContainer();
          InputAttachments inputAttachments = globalContainer.getInputAttachments(); 
          trace = container.getTrace();
          if(inputAttachments.areAttachmentsAvailable())
          {
                    trace.addWarning("Attachments Available");
                    //gets the attachmentIds and store it in an Object array
                    Collection<String> CollectionIDs = inputAttachments.getAllContentIds(true);
                    Object[] arrayObj = CollectionIDs.toArray();
                    //Loops at the input attachments to get the content of the attachment
                    for(int i =0;i<arrayObj.length;i++)
                    {
                              attachmentID =(String)arrayObj[i];
                              trace.addWarning((i+1) + ") Attachment Name: " + attachmentID);
                              if  (i == sequence) {
                                             Attachment att = inputAttachments.getAttachment(attachmentID);
                                             base64content = att.getBase64EncodedContent();
                                             fileType = att.getContentType();
}
                    }
          }
    // } catch (Exception e) {
     //     return e.toString();
     //}
          return fileType + "|" + base64content;

I tried to select and link them based on sequence, but the getInputAttachments function seems to mess up the order. Result is I'm getting the wrong attachments on the orderlines.

Modifying SAP SRM doesn't seem the correct solution. Anybody any clues?

Regards,

Edwin.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers