Skip to main content
10-Marble
January 19, 2024
Question

Trying to get task activity commenter's name via API

  • January 19, 2024
  • 3 replies
  • 1913 views

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.

3 replies

HelesicPetr
22-Sapphire II
22-Sapphire II
January 20, 2024

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

Ben_A10-MarbleAuthor
10-Marble
January 22, 2024

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
23-Emerald I
23-Emerald I
January 22, 2024

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.

joe_morton
18-Opal
18-Opal
March 8, 2024

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()

18-Opal
March 10, 2024

@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