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

Exploring ThingWorx for Completing Work Item tasks


Exploring ThingWorx for Completing Work Item tasks

I am exploring option to complete work item using a Java or Inforengine tasks. Thingworx has out of the box CompleteWorkItems service. It does not take Voting ( Approve / Reject) as an input parameter.  So I am wondering if anyone has explored completing the workitem with a Vote option in WIndchill.

Thanks for your help.



Hi Preeti,

In Windchill there are few API's but unsupported to complete the task with voting:




thanks again Bhushan. I could complete the task using above workComplete method. The workflow moves forward to next activity depending on the routing choices.

I haven't got success yet for creating Voting event.



This works Bhushan.


Hi Preeti,


i am also trying to complete Workflow activity and setting vote using below methods. Activity is getting completed. Voting event is set but process is not moving ahead to next activity as per the vote. Can you please add some light to this? do i need to have any additional method call?

 WorkflowHelper.service.workComplete(workItem, principalRef, events);

WfEventHelper.createVotingEvent(null, wfActivity, workItem, principalRef, comment, events, isSigned, workItem.isRequired());

The following method works for me when called from an expression robot.


     * @param self
     * @param activityPartialName
    public static void completeAssignedActivity(wt.fc.ObjectReference self
            , String activityPartialName) {
        wt.workflow.engine.WfProcess wfProcess = (wt.workflow.engine.WfProcess) self.getObject();
        wt.fc.QueryResult queryResult = new wt.fc.QueryResult();
        try {
            queryResult = wfProcess.getContainerNodes();
        } catch (wt.util.WTException ex) {
        while (queryResult.hasMoreElements()) {
            java.lang.Object obj = queryResult.nextElement();
            if (obj instanceof {
                    = ( obj;
                try {
                    if (!wfAssignedActivity.isComplete()) {
                        java.lang.String currentActivityName = wfAssignedActivity.getName();
                        if (currentActivityName.contains(activityPartialName)) {
                            java.util.Vector<String> v = new java.util.Vector<>();
                            v.addElement("<vote_name>"); // route with same name is required to be defined in the task
                            wt.workflow.engine.WfEngineHelper.service.complete(wfAssignedActivity, v);
                            System.out.println("Completed activity name: " + currentActivityName);
                } catch (wt.util.WTException ex) {

Hi @pjoshi-2 

In the workflow, there should be a code that solve the voting and go forward the process to the right routing. 

A Vote and a route are two different things. Check example in the Promotion Request process where the code is used to chose right route.   


Thanks @BhushanNehe  & @PreetiGupta 

This post really helped me with the workitems task completion.

But I am unable to save the comments that I am passing from Thingworx to the windchill service.

The task completes with the appropriate Routing choice selected but on visiting the completed task from Windchill, cannot see the comments, so basically I am looking for a way to persist the comments when completing task

As of now I have used the below approach that is clearly not working for me (setting the comments to the activity process). Not sure is this is the right way. Any clue/suggestions will be appreciated. Please help

ProcessData data = activity.getContext();
data.setTaskComments("<Comments>"); // setting the updated comments



DId you ever find a way to do this? I'm also trying to set the task comments in code and can't get it to work

The following method works great for me.


 * @param wItem
 * @param comment
public static boolean setComment(WorkItem wItem, String comment) {
	boolean failed = false;
	ProcessData wItemContext = wItem.getContext();
	Transaction trx = null;
	try {
    	trx = new Transaction();

    	if (wItemContext == null) {
    		WfAssignedActivity wfAssignedActivity = (WfAssignedActivity) wItem.getSource().getObject();
    		ProcessData activityContext = wfAssignedActivity.getContext();
    		wItemContext = activityContext.copy();
    	if (comment == null) {
    		comment = "";
        trx = null;
	} catch (Exception e) {
        System.out.println("Exception\n" + e);
	} finally {
        if (trx != null) {
            failed = true;
            System.out.println("Failed to update the comment");
	return failed;


HI James,

Your code works for setting the comments which you can see within the Windchill PDMLink and they will propogate when completing the task through the Windchill interface. But if you complete the task from code using a line like 


WorkflowHelper.service.workComplete(workitem,, events);


the comments are not persisted and basically disappear. This is what sbegum-2 is also saying.


Hello All,


You need to do something like below


WorkItem workItem = ...;

Vector events = new Vector();
// add routing if applicable
// events.addElement("Reject");
WorkflowHelper.service.workComplete(workItem, workItem.getOwnership().getOwner(), events);

// -- start create Voting Event
WTPrincipalReference principalRef= WTPrincipalReference.newWTPrincipalReference(SessionHelper.manager.getPrincipal());
WfActivity myActivity = (WfActivity) workItem.getSource().getObject();
WfAssignedActivityTemplate wfAssignedActivityTemplate=(WfAssignedActivityTemplate) myActivity.getTemplateReference().getObject();
boolean isSigned=wfAssignedActivityTemplate.isSigningRequired();            
String comment = "my_comment";
//unsupported API
WfEventHelper.createVotingEvent(null, myActivity, workItem, principalRef, comment, events, isSigned, workItem.isRequired());
// -- end create Voting Event


Also check this Article :


Thanks Srinivas. Worked like a charm. Great work.