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

Exploring ThingWorx for Completing Work Item tasks

Level 9

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.

Preeti

6 REPLIES 6

Re: Exploring ThingWorx for Completing Work Item tasks

Hi Preeti,

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

wt.workflow.work.WorkflowHelper.service.workComplete

wt.workflow.engine.WfEventHelper.createVotingEvent

Regards,

Bhushan

Re: Exploring ThingWorx for Completing Work Item tasks

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.

:-)

Preeti

Re: Exploring ThingWorx for Completing Work Item tasks

This works Bhushan.

wt.workflow.engine.WfEventHelper.createVotingEvent

Re: Exploring ThingWorx for Completing Work Item tasks

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

Re: Exploring ThingWorx for Completing Work Item tasks

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) {
            System.out.println(ex);
        }
        while (queryResult.hasMoreElements()) {
            java.lang.Object obj = queryResult.nextElement();
            if (obj instanceof wt.workflow.work.WfAssignedActivity) {
                wt.workflow.work.WfAssignedActivity wfAssignedActivity
                    = (wt.workflow.work.WfAssignedActivity) obj;
                try {
                    if (!wfAssignedActivity.isComplete()) {
                        java.lang.String currentActivityName = wfAssignedActivity.getName();
                        if (currentActivityName.contains(activityPartialName)) {
                            @SuppressWarnings("UseOfObsoleteCollectionType")
                            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) {
                    System.out.println(ex);
                }
                
            }
            
        }
        
    }

Re: Exploring ThingWorx for Completing Work Item tasks

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
activity.setContext(data);

 

Thanks!