cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
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

How can I get the username and current date from a Workflow task into some process variables ?

NickD
8-Gravel

How can I get the username and current date from a Workflow task into some process variables ?

I hope this is a really simple question (with a really simple answer) !

How can I capture the username of the person who completes and signs an Approval task as well as the current date & time, and use these to update the value of two process variables (of type string), that are then available to be used in a later step of the workflow to update some CAD file attributes before the files are promoted automatically when the workflow completes ?

I understand we could easily setup a process / task variable (of type string) that is set to be visible and required and use the display name to prompt the user for the correct information to input as well as the required format, but this would be vulnerable to human errors.

Surely the software 'knows' the identity of the user completing the task and can be asked to record the time that they do it, for example with some java code in the Complete Transition tab? If this needs to be done via some intermediate variable(s) to simply the conversion to dumb text strings, then that's just fine.

Best regards,

Nick Drought

2 REPLIES 2

Nick,

Not sure if someone has answered this for you elsewhere but i will give it a shot if not.

Can more than one person sign this task? If so what are you doing with the String to account for that?

We sometimes will get the user comments ( and user name) on a task based on a task name (if its unique) or a tasks routing option (if its unique) or iterate through all the task based on a name/vote to get comments. Depends on what is needed.

If you just want to get the person who clicked complete task then this should help. Place on the complete transion and change user to be whatever you need it to be.

try{

java.util.Enumeration assignments = ((wt.workflow.work.WfAssignedActivity)self.getObject()).getAssignments();

while (assignments != null && assignments.hasMoreElements()) {

wt.workflow.work.WfAssignment assignment = (wt.workflow.work.WfAssignment)assignments.nextElement();

if (assignment.getStatus() == wt.workflow.work.WfAssignmentState.COMPLETED){

java.util.Enumeration w_items = wt.fc.PersistenceHelper.manager.navigate(assignment, wt.workflow.work.WorkItemLink.WORK_ITEM_ROLE, wt.workflow.work.WorkItemLink.class, true);

wt.workflow.work.WorkItem w_item = null;

while (w_items.hasMoreElements()) {

w_item = (wt.workflow.work.WorkItem) w_items.nextElement();

String user=w_item.getCompletedBy(); }

}

}

}catch(wt.util.WTException ee){}

Hope it helps.

Matthew,

Many thanks for your helpful answer, which is clearly a versatile approach for gathering user information.

We have found another method that just gets the current user from wt.session.SessionHelper.manager.getPrincipal and this is doing what we want at the moment (ie. it does just get the person who clicked on complete task).

Thanks again,

Nick Drought

Top Tags