Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
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.
Solved! Go to Solution.
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
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);
}
}
}
for your needs you can start the code on the Complete Task transition.
PetrH
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?
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