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
- You have set up your project in the SAP NetWeaver Developer Studio.
For more information, see Setting Up Your Project .
- You have started a process instance.
For more information, see Starting and Terminating Processes Within a Composite .
- If you want to view design time attachments, you must have created them in advance.
For more information, see Attachments in Including Additional Functionality .
Procedure
- 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(); |
- 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(); |
- 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() ); |
- 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.
- Remove an attachment from the list.
| Removing an Attachment |
|---|
rtList.removeAttachment(rtAttachment.getId()); |
See also: