
The Guided Procedures (GP) framework completes actions when the underlying callable objects indicate that their processing is finished. Using the GP API, you can implement your own logic for triggering action completion outside the GP framework. For example, you can use such functionality if an error prevents the action from completing normally and the process from advancing as it should.
You must have configured your project. For more information, see Setting Up Your Project .
com.sap.caf.eu.gp.context.api.
You need the IGPUserContext instance to authenticate the user who is trying to complete the action. In Web Dynpro you can create the object for the logged-in user. Another option is to use the security API and retrieve the user by his or her logon ID.
| Instantiating IGPUserContext for the Logged-In User in Web Dynpro |
|---|
IUserloggedUser = WDClientUser.getCurrentUser().getSAPUser(); IGPUserContext userContext = GPContextFactory.getContextManager().createUserContext(loggedUser); |
It is a com.sap.caf.eu.gp.process.rt.api.IGPActionCompletionData interface instance. The completion data object is used as a placeholder for all data that needs to be passed to the process context after the action has been completed - output parameters and result states, for example.
The completion data object constructor requires the process and the task IDs, as well as a user context as parameters.
The process and task identifiers are strings, which you can check in the process URL if you start the GP runtime outside the portal. You start the runtime using the following URL: http:// <host> : <port> /webdynpro/dispatcher/sap.com/caf~eu~gp~ui~rtwc/WorkCenterRunTime
| Creating an IGPActionCompletionData Instance |
|---|
importcom.sap.caf.eu.gp.process.rt.api.IGPActionCompletionData; importcom.sap.caf.eu.gp.process.rt.api.IGPRuntimeManager; ... publicvoid onActionStopAction(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent ) {... StringprocessID = wdContext.currentContextElement().getProcessID(); StringactionID = wdContext.currentContextElement().getActionID(); IGPActionCompletionDatacompletionData = rtManager.createActionCompletionData(processID, actionID, userContext); ... } |
To retrieve the root output structure, use the completion data object's getOutputParameters() method. Then you can set the individual attribute values.
| Populating the Output Structure with Values |
|---|
IGPStructurestruct = completionData.getOutputStructure(); struct.setAttributeValue("name", wdContext.currentContextElement().getName()); struct.setAttributeValue("address", wdContext.currentContextElement().getAddress()); |
The attributes' technical names and types must match exactly the ones that have been defined for the action at design time. You can also retrieve this information using the GP interfaces. Using the process and action identifiers, you can retrieve the action instance from the GP runtime manager and then get the action template. It contains the object's metadata and enables you to retrieve information about the action's output parameters, result states, and process exceptions.
| Retrieving Information about Action's Parameters, Result States, or Process Exceptions |
|---|
IGPActionInstanceinstance = rtManager.getActionInstance(processID, actionID, userContext); if(instance.getTemplate().isAction()){//the action template IGPActionaction = (IGPAction) instance.getTemplate(); //a collection of IGPAttributeInfo objects Collectionoutput = action.getOutputParameters().getAttributes(); Iteratoritr = output.iterator(); while(itr.hasNext()){IGPAttributeInfo attr = (IGPAttributeInfo)itr.next(); String name = attr.getTechName(); int type = attr.getType(); } ... //an array of IGPResultStateInfo objects IGPResultStateInfo[]states = action.getResultStates(); for(int i=0; i<states.length; i++){String resultState = states[i].getName(); ... } |
You can end an action using one of the following statuses:
You can retrieve the exact result state and process exception names as described for the attributes' names and types in the previous step.
| Setting the Completion Status |
|---|
completionData.setState( IGPActionCompletionData.RESULT_STATE_COMPLETED_DONE_ONLY); |
An action is either executed in the background, or exposes a user interface. For example, actions encapsulating composite forms are handled in the background, while those created for Web Dynpro callable objects are visual.
The GP framework handles the two action types differently so you must set the type explicitly.
| Setting the Action Type |
|---|
completionData.setType(IGPActionCompletionData.ACTIVITY_TYPE_USER); |
| Completing the Action |
|---|
rtManager.completeAction(completionData); |
The action is completed, and the process execution either continues, or the process state is set to erroneous if you have completed the action with a technical exception.