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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Trying to get task activity commenter's name via API

Ben_A
7-Bedrock

Trying to get task activity commenter's name via API

Windchill 12.0.2

 

I need help determining who wrote a workflow task comment immediately after the task is completed. I am able to get the comment they entered with the following code. But, I have been unable to find a way to get the name of the user that entered it.

 

 

wt.workflow.work.WfAssignedActivity activity = (wt.workflow.work.WfAssignedActivity) self.getObject();
wt.workflow.engine.ProcessData actData = activity.getContext();
task_comment = actData.getTaskComments();

 

Seams like it would pretty straight forward but, ProcessData.GetName() returns a list[] of attributes and none of the other methods under ProcessData appear to give me what I'm after.

6 REPLIES 6
HelesicPetr
21-Topaz II
(To:Ben_A)

Hi @Ben_A 

Go back and take the info from the task, who finished it. 

I wrote that code in the past but I would be able to find it later. 

edited:

try this code

 

wt.fc.collections.WTArrayList auditCol = (wt.fc.collections.WTArrayList) wt.workflow.engine.WfEngineHelper.service.getVotingEvents((wt.workflow.engine.WfProcess) activity.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());
	System.out.println("***Transition Expression: User name= " + ((WTUser)audit.getUserRef().getObject()).getName());
	
	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);
		}
	}
}

 

PetrH

Hi @HelesicPetr 

I am unable to get this to work. The array returned by getVotingEvents is always empty.

 

MethodServer log:

***Transition Expression: Audit = []

 activity is currently defined as a WfAssignedActivity and that could be the problem. How is activity defined in your code?

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

 

avillanueva
22-Sapphire I
(To:Ben_A)

If this is run from a transition, is it possible its not persisted yet when you make the call? Try from an expression robot that immediately follows the task. If esignature is used, data can also be stored in the Signature History.

rhart
14-Alexandrite
(To:avillanueva)

That could work, calling from a wf expression in a transition.

The active user, the user committing the comment and the user completing the task are all the same user.

 

You can get the principal of the active user

 

 

wt.workflow.work.WfAssignedActivity wfAct = ((wt.workflow.work.WfAssignedActivity)(self.getObject()));
wt.team.Team team = (wt.team.Team) wfAct.getParentProcess().getTeamId().getObject();
wt.org.WTPrincipal activeUser = wt.session.SessionHelper.getPrincipal();

 

 

joe_morton
17-Peridot
(To:Ben_A)

Try this:

https://www.ptc.com/en/support/article/CS385221?source=search

 

Once you have the user, they show using getEMail(), but there's another supported API getFullName()

d_graham
17-Peridot
(To:Ben_A)

@Ben_A 

I wrote code to get the user and the comment immediately upon the user completing the task.

Works perfectly.

Currently the code simply writes to the log but could do whatever you need it to do.

Below is from the log:

 

wt.system.out wcadmin - User: Site, Administrator
wt.system.out wcadmin - Comment: These are my comments for testing only.
 wt.system.out wcadmin - 1. zzz
 wt.system.out wcadmin - 2. xxx
 wt.system.out wcadmin - Task Completed

 

Where/how do you intend to use the data?  I'm thinking you what this info returned to the workflow to do something with it, like pass the info to another task for the next person to read.

 

What's the plan?

 

If you need help send me an email from your work email account to windchill.developer@yahoo.com 

I write code for lots of people. Lots of experience doing whatever.

 

David

Top Tags