Custom WDJ Application to process Tasks using BPM JAVA API in NWDS 7.3
Hi Everyone,
This is my first blog.Hope you all will read it & give me your valuable suggestions regarding the content.
The objective of the blog is to create a very simple custom WDJ Application to process tasks using BPM JAVA API in NWDS 7.3 instead of using Universal Worklist provided by SAP. Though SAP provided us an user inbox under Universal Worklist Tab in Portal.But some time client want a customized user inbox created using WDJ Application.With the Business Process Management (BPM) application programming interfaces (API’s), we can customize and enhance the way we use business processes and execute tasks and can design user friendly inbox for better user experience and performances.
Steps:
1.0.Install SAP Net weaver Developer Studio (NWDS 7.3).
2.0.BPEM End User & Every User Core Role should be assigned to user.
3.0.Create the Web Dynpro Java Application in NWDS 7.3
3.6. Create one action “OnSelectTask” and implemented the following code inside it.
public void onActionOnSelectTask (com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@beginonActionOnSelectTask(ServerEvent)
String url=wdContext.currentTaskElement().getURL();
wdThis.wdGetNew1CompController().LinkToOpenTask(url);
//@@end
}
3.7.In Component Controller implemented following codes in wdDoInit() and LinkToOpenTask( java.lang.String url )methods.
public void wdDoInit()
{
//@@beginwdDoInit()
ArrayList<TaskDetail> testList = new ArrayList<TaskDetail>();
try {
//To get the logged on user details
IUser user = UMFactory.getAuthenticator().getLoggedInUser();
String firstName = user.getFirstName();
String lastName = user.getLastName();
String userName = firstName != null ? firstName + " " + lastName: lastName;
wdComponentAPI.getMessageManager().reportSuccess("Welcome "+userName);
// Retrieve the TaskInstanceManager.
TaskInstanceManager taskInstanceManager = BPMFactory.getTaskInstanceManager() ;
// Build the set of statuses to query.
Typically, use READY, RESERVED and IN_PROGRESS statuses, which mean that the tasks are ready to work on and the user is a potential or actual owner of the task.
HashSet<Status> statuses = new HashSet<Status> ();
statuses.add(Status.READY);
statuses.add(Status.RESERVED);
statuses.add(Status.IN_PROGRESS);
// Query those statuses.
The returned set contains TaskAbstracts, which are basic descriptions of a task instance and thus contain the required information to build up the task worklist. The method always executes the query for the user who is currently logged in and returns texts in the locale which is set for the user.
Set<TaskAbstract> myTasks = taskInstanceManager.getMyTaskAbstracts(statuses);
//Use Iterator of type TaskAbstract to loop trough the myTasks.
Iterator<TaskAbstract> taskIter = myTasks.iterator();
URL taskExecutionURL=null;
while(taskIter.hasNext()){
//Get single Task
TaskAbstract myTask = taskIter.next();
// Get the ID of the Task.
java.net.URI taskInstanceId = myTask.getId();
// Use the ID of a task instance to generate the URL of the task execution UI. This can then be opened as an action, for example when the user clicks the task.
taskExecutionURL = taskInstanceManager.generateTaskExecutionUrl(taskInstanceId);
TaskDetail taskDetail = taskInstanceManager.getTaskDetail(taskInstanceId);
testList.add(taskDetail);
// Filter the tasks for the current year “2013”
if((""+myTask.getCreatedTime()).contains("2013") ){
IPublicNew1Comp.ITaskElement Ele =wdContext.nodeTask().createTaskElement();
Ele.setID((""+myTask.getId()).substring((""+myTask.getId()).lastIndexOf("/")+1));
Ele.setName(myTask.getPresentationName());
Ele.setCreationDate(""+myTask.getCreatedTime());
Ele.setURL(taskExecutionURL.toString());
wdContext.nodeTask().addElement(Ele);
}}
catch (BPMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
wdComponentAPI.getMessageManager().reportException(e);
}
//@@end
}
public void LinkToOpenTask( java.lang.String url ) {
//@@beginLinkToOpenTask()
//Open window to view the Task
IWDWindow window = wdComponentAPI.getWindowManager().createNonModalExternalWindow(url, "Task",false);
window.show();
//@@end
}
3.8. Build,Deploy & Run the application
4.0. Result:
4.1. | Logon Screen:- | ![]() |
4.2. | User will be able to see all the listed tasks and click on selected task and perform it. | ![]() |
Thanks & Regards,
Patralekha Sur
Very very useful document.
Thanks for sharing. Very helpful!