Skip to main content
16-Pearl
March 19, 2015
Solved

Requiring comments to be entered in a task before allowing complete task

  • March 19, 2015
  • 5 replies
  • 5485 views

Does anyone have code that will require comments be entered before allowing a workflow task to be completed? I am looking at putting something in the transitions tab of that specific node, not global code.

Best answer by BenPerry

Greg, I think this code will work just fine for non-change objects too. Can you give it a try.

In my case, I wanted to capture the comments and assign them to a workflow variable, "detailedChangeDescription". But if you're not interested in that, you can possibly try something like this:

wt.workflow.work.WfAssignedActivity activity = (wt.workflow.work.WfAssignedActivity) self.getObject();

wt.workflow.engine.ProcessData actData = activity.getContext();

if (actData.getTaskComments().length() < 10) {

throw new wt.util.WTException(new Throwable(new String("Hey user - please type something into the Comments field!")));

}

Of course you can adjust the quantity of characters it looks for too, based on your need. I wanted the user to enter at least 10 characters. Therefore .length() < 10. You can change that if you wish.

5 replies

1-Visitor
March 20, 2015

Greg, is there any specific reason you want to do this via transition tab. As you might be aware, it is easier to acheive using client side Java Script validation.

GregOlson16-PearlAuthor
16-Pearl
March 20, 2015

Prabhash,

I would like to do this at the transitions tab level as I do not want to require comments all the time....actually for this specific workflow I don't want to require comments on all routing options.

12-Amethyst
March 20, 2015

I haven't set up a test for this, but if you are able to access the WorkItem IDA2A2 from the transitions tab (or wherever you want to run the validation from) you could query the database for the comments using a Query Spec. I'm assuming that the comments are persisted once the user clicks the "Complete Task" button.

QuerySpec qs = new QuerySpec();

int classIndex = qs.appendClassList(WfVotingEventAudit.class, false);

ClassAttribute ca = new ClassAttribute(WfVotingEventAudit.class, WfVotingEventAudit.USER_COMMENT);

SearchCondition sc = new SearchCondition(WfVotingEventAudit.class, WfVotingEventAudit.WORK_ITEM_REFERENCE + "." + WTAttributeNameIfc.REF_OBJECT_ID, SearchCondition.EQUAL, new Long("12345")); //Change to WorkItem ida2a2

qs.appendSelect(ca, new int[]{classIndex}, false);

qs.appendWhere(sc, new int[]{classIndex});

If the comments are empty, follow with logic to force comments.

1-Visitor
September 1, 2016

I'm assuming that the comments are persisted once the user clicks the "Complete Task" button.

If this is true then this can be done easily.

15-Moonstone
March 20, 2015

Greg,

I put this in my Transitions tab. detailedChangeDescription is a global String variable in the workflow. But serves as an example for what you're after. In the example, I am checking to make sure the string length is at least 10 characters. You could check for only 1 if you wish - or use whatever logic you want to.

wt.workflow.work.WfAssignedActivity activity = (wt.workflow.work.WfAssignedActivity) self.getObject();

wt.workflow.engine.ProcessData actData = activity.getContext();

detailedChangeDescription = actData.getTaskComments();

if (detailedChangeDescription.length() < 10) {

throw new wt.util.WTException(new Throwable(new String("Please enter a detailed description in the Comments field.")));

}

This is a leverage of these 2 articles:

https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS185827

https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS182596

GregOlson16-PearlAuthor
16-Pearl
March 23, 2015

Thanks for the code Ben.....I am not a code guy, I am sure this would work great for change items. Would you happen to know what I would replace in the code for a non- change workflow, its just a WT doc with a simple routing.

Greg

BenPerry15-MoonstoneAnswer
15-Moonstone
March 23, 2015

Greg, I think this code will work just fine for non-change objects too. Can you give it a try.

In my case, I wanted to capture the comments and assign them to a workflow variable, "detailedChangeDescription". But if you're not interested in that, you can possibly try something like this:

wt.workflow.work.WfAssignedActivity activity = (wt.workflow.work.WfAssignedActivity) self.getObject();

wt.workflow.engine.ProcessData actData = activity.getContext();

if (actData.getTaskComments().length() < 10) {

throw new wt.util.WTException(new Throwable(new String("Hey user - please type something into the Comments field!")));

}

Of course you can adjust the quantity of characters it looks for too, based on your need. I wanted the user to enter at least 10 characters. Therefore .length() < 10. You can change that if you wish.

1-Visitor
March 23, 2015

Hello Greg,

Were you successful with the above solutions proposed, let me know even I would like to implement this idea

Thanks

Athmanand

1-Visitor
March 23, 2015

Our code requires comments if you vote No or Return to Creator but not if you vote Yes.

15-Moonstone
March 23, 2015

Mary,

In your case, you probably have the Routing tab set up similar to the 1st screenshot below, correct? In that case, you can paste the java code into both the No and the Return_to_Creator transitions on the Transitions tab, like the 2nd screenshot below.

Please note the UNDERSCORES in the Return_to_Creator route. Unfortunately if you use code in the Transitions tab on a custom route, there cannot be any spaces in the name of the route.

2015-03-23_17-31-34.png

2015-03-23_17-32-18.png