cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Workflow: make comments mandatory in an activity

HenriMarchal
7-Bedrock

Workflow: make comments mandatory in an activity

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.

ACCEPTED SOLUTION

Accepted Solutions

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.");
}
}
}
}
}
}

View solution in original post

2 REPLIES 2

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.");
}
}
}
}
}
}

It just worked fine. Thank you !

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

Announcements


Top Tags