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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Code to extact who has accepted a task

Ben_A
8-Gravel

Code to extact who has accepted a task

I need help writing some code that will tell me who has accepted an activity task (but may not have completed that task yet). The code needs to run in a Workflow expression bot. I want to send an email to only that person. The task may have initially been assigned to 5 people, then one person accepts the task.

 

If no one has accepted then the email will go to all 5.

We are using Windchill 12.

 

1 ACCEPTED SOLUTION

Accepted Solutions
HelesicPetr
22-Sapphire I
(To:Ben_A)

Hi @Ben_A 

Following code helps you. 

you just need to use the asigment variable from previous code.

wt.fc.collections.WTHashSet assigmentSet = new wt.fc.collections.WTHashSet();
assigmentSet.add(asigment);
wt.fc.collections.WTCollection workItemCollation = wt.workflow.work.WorkflowHelper.getWorkItemsFromAssignments(assigmentSet,wt.workflow.work.WfAssignmentState.ACCEPTED);
for (Object workItemSet:workItemCollation)
{
	if (workItemSet instanceof wt.workflow.work.WorkItem)
	{
		wt.workflow.work.WorkItem workI = (wt.workflow.work.WorkItem) workItemSet;
		workI.getOwnership().getOwner().getDisplayName();
		workI.getOwnership().getOwner().getName();
		workI.getActionPerformed();
	}
}

PetrH

View solution in original post

5 REPLIES 5
HelesicPetr
22-Sapphire I
(To:Ben_A)

Hi @Ben_A 

It depends where you want to run the code. Task or Workflow. 

 

here is example how I get the vote from in the workflow task when the task starts. 

I use it for showing comments from the previous tasks

 

wt.fc.collections.WTArrayList auditCol = (wt.fc.collections.WTArrayList) wt.workflow.engine.WfEngineHelper.service.getVotingEvents((wt.workflow.engine.WfProcess) ((wt.workflow.work.WfAssignedActivity) self.getObject()).getParentProcess(), null, null, null);
System.out.println("***Transition Expression: Audit = " + auditCol.toString());

java.util.Iterator auditEvents = auditCol.persistableIterator();
String comments = "";
while (auditEvents.hasNext())
{
	wt.workflow.engine.WfVotingEventAudit audit = (wt.workflow.engine.WfVotingEventAudit) auditEvents.next();
	System.out.println("***Transition Expression: User vote = " + audit.getEventList());
	System.out.println("***Transition Expression: User comment = " + audit.getUserComment());
	if (audit.getEventList() != null)
	{
		int auditSize = audit.getEventList().size();
		for (int i = 0; i < auditSize; i++)
		{
			Object eventVote = audit.getEventList().get(i);
			System.out.println("vote = " + eventVote);
		}
	}
}

 

HelesicPetr_0-1700722609709.png

 

for your needs you can start the code on the Complete Task transition. 

 

PetrH

PS: I miss understand the accepted 😄 I was sure it is about voting  not accepting the task from task table 

HelesicPetr_0-1700743619399.png

 

PetrH

@Ben_A 

Here is code to get status if the task is accepted or not

wt.workflow.work.WfAssignedActivity activity = (wt.workflow.work.WfAssignedActivity) self.getObject();
QueryResult assignments = (QueryResult) activity.getAssignments();
while (assignments.hasMoreElements())
{
	Object resultObj = assignments.nextElement();
	if (resultObj instanceof wt.workflow.work.WfAssignment)
	{
		wt.workflow.work.WfAssignment asigment = (wt.workflow.work.WfAssignment) resultObj;
		WfAssignmentState wiStatus = asigment.getStatus();
		Object sourceObj = asigment.getSource().getObject();
		System.out.println("***Transition Expression: wiStatus = " + wiStatus);
	}
}

PetrH

@HelesicPetrThanks for the example of how to determine if the task has been accented by someone or not. That got me half way to where I need to be. Did you know of a way to determine by whom the task is accepted?

HelesicPetr
22-Sapphire I
(To:Ben_A)

Hi @Ben_A 

Following code helps you. 

you just need to use the asigment variable from previous code.

wt.fc.collections.WTHashSet assigmentSet = new wt.fc.collections.WTHashSet();
assigmentSet.add(asigment);
wt.fc.collections.WTCollection workItemCollation = wt.workflow.work.WorkflowHelper.getWorkItemsFromAssignments(assigmentSet,wt.workflow.work.WfAssignmentState.ACCEPTED);
for (Object workItemSet:workItemCollation)
{
	if (workItemSet instanceof wt.workflow.work.WorkItem)
	{
		wt.workflow.work.WorkItem workI = (wt.workflow.work.WorkItem) workItemSet;
		workI.getOwnership().getOwner().getDisplayName();
		workI.getOwnership().getOwner().getName();
		workI.getActionPerformed();
	}
}

PetrH

Top Tags