Overview
In some cases, people like e-mail and prefer to see much information in it. However, NetWeaver BPM7.2 cannot permit editing content of task notification mail sent by Human Activity. Also it is not easy to send a task execution URL by Notification Activity.
I made a trick to send modifiable task notification e-mail with task launcher URL. End users can see their own task screen when they just click a URL in e-mail. I will explain how to do it.
Process
First, I created a very simple sample process like below.
In this process, a task identification key is generated from current date and time at Start event. It is sent to end user as a part of task launcher URL.
Notification Activity
Here is detail of Notification Activity. Body of its message contains task launcher URL. Note that, task identification key is sent as a parameter of URL. Hence launcher can find actual task instance from Universal Work List (UWL).
Human Activity
Task identification key also have to be passed to Human Activity. Make sure your Input Mapping is valid.
Then task is prepared to have a key in its texts. In this sample, key is set at the tail of description.
Task Launcher
Next, I created a WebDynpro component and implemented task launcher. There is two important methods, findTask and launchTask. Thanks to Kenichi Unnai and his blog, I could realize my purpose.
You have to create these two methods, and call them in ComponentController.wdDoInit().
findTask method
In this method, you have to find a task instance in UWL and generate an actual URL. As described above, you can see task identification key in description of UWL item.
Source code is here. Note that it is simplified for explanation.
//begin sample code ----
public void findTask( ) throws WDUMException, UWLException, WDURLException {
// get task key from URL parameter
String taskKey = WDProtocolAdapter.getProtocolAdapter().
getRequestObject().getParameter("TaskKey");
if (taskKey == null || taskKey.length() == 0) {
wdComponentAPI.getMessageManager().
reportException("Can not get 'TaskKey' parameter");
return;
}
// create UWL context
UWLContext uwlContext = new UWLContext();
IUser user = WDClientUser.getCurrentUser().getSAPUser();
uwlContext.setUser(user);
uwlContext.setLocale(user.getLocale() !=
null ? user.getLocale() : Locale.getDefault());
// get UWL service
IUWLService uwlService = (IUWLService) PortalRuntime.getRuntimeResources().
getService(IUWLService.ALIAS_KEY);
// begin session
IUWLSession uwlSession =
uwlService.beginSession(uwlContext, SESSION_IDLE_TIMEOUT);
//build expression
Expression expStatusNew = new Expression(
Item.STATUS, StatusEnum.NEW.toString(), ComparatorEnum.EQUAL_TO);
Expression expStatusProg = new Expression(
Item.STATUS, StatusEnum.INPROGRESS.toString(), ComparatorEnum.EQUAL_TO);
ArrayList expList = new ArrayList();
expList.add(expStatusNew);
expList.add(expStatusProg);
CompoundExpression exp = new CompoundExpression(expList, null, null, true);
// iterate over all UWL items
IUWLItemManager itemManager = uwlService.getItemManager(uwlContext);
UWLView uwlView = uwlService.getViewManager(uwlContext).
getViewForItemType(ItemType.UWL_ITEM, uwlContext);
QueryResult result = itemManager.refreshCacheAndGetItems(
uwlContext, uwlView, queryProperty, exp);
ItemCollection items = result.getItems();
List list = items.list();
for (Item item : list) {
item = itemManager.getItemByUwlId(uwlContext, item.getInternalId());
String description = item.getDescription();
if (description != null && description.endsWith(taskKey)) {
String executionURL = WDURLGenerator.getApplicationURL(
BPM_TASK_COMP_NAME, BPM_TASK_PART_NAME, item.getAttributes());
//store actual URL to WebDynpro context
wdContext.currentBPMTaskElement().setUrl(executionURL);
break;
}
}
// end session
uwlService.endSession(uwlContext);
}
public static final int SESSION_IDLE_TIMEOUT = 60;
public static final String BPM_TASK_COMP_NAME =
"sap.com/tc~bpem~wdui~taskinstance";
public static final String BPM_TASK_PART_NAME =
"ATaskExecution";
//end sample code ----
launchTask method
This method redirects end user to the actual URL. It just triggers Exit Plug with Url parameter.
//begin sample code ----
public void launchTask( ) {
String url = wdContext.currentBPMTaskElement().getUrl();
if (url != null && url.length() > 0) {
//triggers Exit Plug with actual URL
wdThis.wdGetUWLRedirectComponentWindowController().wdFirePlugLaunchTask(url);
}
}
//end sample code ----
Conclusion
Task notification e-mail is completely modifiable. It can contain any information in a process instance.
End usre can see a task screen easily, just click a URL in a e-mail.
Enjoy!