Skip to main content
1-Visitor
July 25, 2011
Solved

Workflow: make comments mandatory in an activity

  • July 25, 2011
  • 1 reply
  • 4455 views

Hello,

I'ld like to make the "comments" field mandatory in an assigned activity.

But not in all cases so I cannot just custom the basic jsp. It is just for certain activities and when the user rejects the activity. If he chooses "comlete" he doesn't have to put a comment.

I achieved it by adding a writtable "comment2" variable and some validation on the "reject" transition.

But it is misleading for the user to have at once the field "comment2" and the original "comments" field.

Have you an idea how to implement this requirement ?

thank you.

Best answer by MatthewKnight

Do something like the following......

For 9.1 (idk what the property looks like in 8/10)

in wt.properties,

wt.services.service.10040=com.ptc.netmarkets.work.NmWorkItemService/mypackage.MyNmWorkItemService

Try to give your activity a unique name (no other templates use an activity with this name) or come up with your own way to distinguish the workitem.

Create your NmWorkItemSerivce class:

package mypackage;
import java.util.HashMap;
import wt.fc.ObjectReference;
import wt.fc.Persistable;
import wt.util.WTException;
import wt.workflow.engine.WfActivity;
import wt.workflow.work.WorkItem;
import com.ptc.netmarkets.util.beans.NmCommandBean;
import com.ptc.netmarkets.work.StandardNmWorkItemService;
public class MyNmWorkItemService extends StandardNmWorkItemService {
public static MyNmWorkItemService newMyNmWorkItemService() throws WTException {
MyNmWorkItemService service = new MyNmWorkItemService();
service.initialize();
return service;
}
@Override
public void complete(NmCommandBean commandBean, HashMap map) throws WTException {
validateComplete(commandBean, map);
super.complete(commandBean, map);
}
private void validateComplete(NmCommandBean commandBean, HashMap map) throws WTException {
com.ptc.netmarkets.model.NmOid nmoid = commandBean.getPageOid();
WorkItem workitem = getWorkItem(nmoid);
ObjectReference sourceReference = workitem.getSource();
if(sourceReference != null) {
Persistable sourceObject = sourceReference.getObject();
if(sourceObject != null && sourceObject instanceof WfActivity) {
WfActivity activity = (WfActivity)sourceObject;
String activityName = activity.getName();
if("Uniqely Named Activity".equals(activityName)) {
HashMap cbMap = commandBean.getMap();
String comments = (String)cbMap.get("comments");
if(comments == null || comments.trim().length() == 0) {
throw new WTException("Comments are required.");
}
}
}
}
}
}

1 reply

1-Visitor
July 25, 2011

Do something like the following......

For 9.1 (idk what the property looks like in 8/10)

in wt.properties,

wt.services.service.10040=com.ptc.netmarkets.work.NmWorkItemService/mypackage.MyNmWorkItemService

Try to give your activity a unique name (no other templates use an activity with this name) or come up with your own way to distinguish the workitem.

Create your NmWorkItemSerivce class:

package mypackage;
import java.util.HashMap;
import wt.fc.ObjectReference;
import wt.fc.Persistable;
import wt.util.WTException;
import wt.workflow.engine.WfActivity;
import wt.workflow.work.WorkItem;
import com.ptc.netmarkets.util.beans.NmCommandBean;
import com.ptc.netmarkets.work.StandardNmWorkItemService;
public class MyNmWorkItemService extends StandardNmWorkItemService {
public static MyNmWorkItemService newMyNmWorkItemService() throws WTException {
MyNmWorkItemService service = new MyNmWorkItemService();
service.initialize();
return service;
}
@Override
public void complete(NmCommandBean commandBean, HashMap map) throws WTException {
validateComplete(commandBean, map);
super.complete(commandBean, map);
}
private void validateComplete(NmCommandBean commandBean, HashMap map) throws WTException {
com.ptc.netmarkets.model.NmOid nmoid = commandBean.getPageOid();
WorkItem workitem = getWorkItem(nmoid);
ObjectReference sourceReference = workitem.getSource();
if(sourceReference != null) {
Persistable sourceObject = sourceReference.getObject();
if(sourceObject != null && sourceObject instanceof WfActivity) {
WfActivity activity = (WfActivity)sourceObject;
String activityName = activity.getName();
if("Uniqely Named Activity".equals(activityName)) {
HashMap cbMap = commandBean.getMap();
String comments = (String)cbMap.get("comments");
if(comments == null || comments.trim().length() == 0) {
throw new WTException("Comments are required.");
}
}
}
}
}
}
1-Visitor
July 28, 2011

It just worked fine. Thank you !

With this solution, we've got access to NmCommandBean object and then to a lot of things.