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.
● 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.
...
1. Instantiate the runtime manager if you have not done so previously.
Instantiating the Runtime Manager |
import com.sap.caf.eu.gp.process.api.GPProcessFactory; import com.sap.caf.eu.gp.process.rt.api.IGPRuntimeManager;
IGPRuntimeManager runtimeManager = GPProcessFactory.getRuntimeManager();
|
2. 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 |
import com.sap.caf.eu.gp.process.rt.api.IGPRuntimeAttachmentList; import com.sap.caf.eu.gp.process.api.IGPProcessInstance; import com.sap.security.api.IUser; import java.util.Enumeration; import com.sap.caf.eu.gp.attachment.api.IGPAttachment;
// retrieve attachment list IGPRuntimeAttachmentList rtList = runtimeManager.getAttachmentList(processInstance.getID(), null, user); // retrieve a single attachment Enumeration e = rtList.elements(); IGPAttachment attachment = (IGPAttachment) e.nextElement();
|
The list contains both design time and runtime attachments. You cannot modify the design time attachments.
3. Add new runtime attachments to the list.
Adding a Runtime Attachment |
IGPAttachment rtAttachment = rtList.add( "Display Name", "Filename", // attachment type IGPAttachment.TYPE_URL, "Creator", // raw byte content of attachment "content".getBytes() ); |
4. 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.
5. Remove an attachment from the list.
Removing an Attachment |
rtList.removeAttachment(rtAttachment.getId());
|
If you try to remove a design time attachment from the list, an invocation exception is raised.
See also: