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

Community Tip - You can change your system assigned username to something more personal in your community settings. X

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

GregOlson
16-Pearl

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

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.

ACCEPTED SOLUTION

Accepted Solutions
BenPerry
15-Moonstone
(To:GregOlson)

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.

View solution in original post

10 REPLIES 10
Prabhash
12-Amethyst
(To:GregOlson)

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.

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.

jmomber
12-Amethyst
(To:GregOlson)

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.

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.

BenPerry
15-Moonstone
(To:GregOlson)

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

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

BenPerry
15-Moonstone
(To:GregOlson)

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.

Anand
12-Amethyst
(To:GregOlson)

Hello Greg,

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

Thanks

Athmanand

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

BenPerry
15-Moonstone
(To:mbonitati)

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

Announcements


Top Tags