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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Programmatically assign a task participant


Programmatically assign a task participant

Hello, all!


For a current workflow task, how do I programmatically add a user and assign them the current task (add them to the current task pool)?


So.  Adding users to a role via api.  Check.  There are a bunch of ways to do this, actually.  The two main ways were getting the team for the object and adding and getting the process team (which I figure is the same in this case?) and adding the participant.


I can add the participant, but the task for that role is not generating.  As always, I figure I am missing something obvious.......


Latest iteration I was trying:


private String assignUserToRole(WTChangeOrder2 coIn,String roleNameIn,String userNameToAdd){
	Vector<Role> rolesToReturn = new Vector<Role>();
	StringBuilder dataToReturn = new StringBuilder();
		Team curCNTeam = TeamHelper.service.getTeam(coIn);
		rolesToReturn = curCNTeam.getRoles();
		for(Role curRole:rolesToReturn){
				QuerySpec qs = new QuerySpec(;
				qs.appendWhere(new SearchCondition(,, SearchCondition.LIKE, userNameToAdd,false), null);

				StatementSpec statementSpec = (StatementSpec) qs;
				QueryResult qr = PersistenceHelper.manager.find(statementSpec);
				if (qr.size() > 0) { user = ( qr.nextElement();
					TeamHelper.service.addRolePrincipalMap(curRole, user, curCNTeam);
	catch(WTException e){
		dataToReturn.append("Error adding " + userNameToAdd + " to role " + roleNameIn);

	return dataToReturn.toString();

Hi Brian,


Workflow tasks can be modified if you can get the WfAssignment. From the WfAssignment you can try the following:



wfAssignment.setAssignee(WfAssignee assignee);


I believe that will work. Getting the WfAssignment itself can be difficult though. You'll have to query for the workflow task name:



* This method returns all workflow activities of the given name from the
* given workflow
* @param self This is an ObjectReference to a workflow.
* @param activityName This is a String that contains the name of the workflow
* activity to find. An example is "Submit Change Notice".
* @return Latest of WfAssignedActivity that the method searched for.
WfProcess proc = (WfProcess) self.getObject();
Class<WfAssignedActivity> qc = WfAssignedActivity.class;
QuerySpec qs = new QuerySpec();
int idx = qs.addClassList(qc, true);
SearchCondition sc = new SearchCondition(WfAssignedActivity.class, "",
SearchCondition.EQUAL, proc.getPersistInfo().getObjectIdentifier().getId());
qs.appendWhere(sc, new int[]{idx});
QueryResult qr = PersistenceHelper.manager.find((StatementSpec) qs);
WfAssignedActivity activity;
Timestamp modtime=proc.getCreateTimestamp();
while (qr.hasMoreElements()) {
Persistable[] ar = (Persistable[]) qr.nextElement();
activity = (WfAssignedActivity) ar[idx];
if (activity.isComplete()) {
if (activity.getName().equalsIgnoreCase(activityName) && activity.getModifyTimestamp().after(modtime) ) {
wfpvReviewActivity = activity;


You'll have to clean that up a bit but that should return the workflow activity. Next you can use:

QueryResult wfAssignments = (QueryResult) wfpvReviewActivity.getAllAssignments();

This will get a QueryResult of all assignments. You can then iterate through to get the right one.


I'm not certain that this will work but it might help you get on the right track.


Top Tags