Managing Runtime Attachments Using the GP API

Use

With the Guided Procedures (GP) runtime API, you can dynamically add or remove attachments to the processes you have initiated at runtime.

You can also view design time attachments but you cannot modify them.

Prerequisites

Procedure

  1. Instantiate the runtime manager if you have not done so previously.

Instantiating the Runtime Manager
importcom.sap.caf.eu.gp.process.api.GPProcessFactory;
importcom.sap.caf.eu.gp.process.rt.api.IGPRuntimeManager;
 
IGPRuntimeManagerruntimeManager = GPProcessFactory.getRuntimeManager();
  1. Retrieve the list of process attachments.

    You must supply the process instance ID and the relevant user. You may enter null for the activity instance ID, since these are only the attachments at process level.

Retrieving Attachments of a Process Instance
importcom.sap.caf.eu.gp.process.rt.api.IGPRuntimeAttachmentList;
importcom.sap.caf.eu.gp.process.api.IGPProcessInstance;
importcom.sap.security.api.IUser;
importjava.util.Enumeration;
importcom.sap.caf.eu.gp.attachment.api.IGPAttachment;
 
// retrieve attachment list
IGPRuntimeAttachmentListrtList = runtimeManager.getAttachmentList(processInstance.getID(), null, user);
// retrieve a single attachment
Enumeratione = rtList.elements();
IGPAttachmentattachment = (IGPAttachment) e.nextElement();
  1. Add new runtime attachments to the list.

Adding a Runtime Attachment
IGPAttachmentrtAttachment = rtList.add(
                                     "Display Name",
                                     "Filename",
                                     // attachment type
                                     IGPAttachment.TYPE_URL,
                                     "Creator",
                                     // raw byte content of attachment
                                     "content".getBytes()
                                     );
  1. Save the attachment list.

Persisting the Attachment List
runtimeManager.persistAttachmentList(processInstance.getID(),null, rtList, user);

The algorithm behind the persistAttachmentList() method ensures that only the relevant changes are saved each time you use it.

  1. Remove an attachment from the list.

Removing an Attachment
rtList.removeAttachment(rtAttachment.getId());

See also:

Attachment Attributes