Advanced Customization > Business Logic Customization > Customizing Change Management > Change Workflow Closure > Solution > Procedure – Update Workflow to use Synchronized Closure
  
Procedure – Update Workflow to use Synchronized Closure
The following example will start with a basic workflow that goes from Under Review to Resolved state after a review task is completed with synchronized closure.
1. Select the workflow template Properties link. Go to the Variables tab and add a new boolean variable named handlesClosure with the default value set to true.
2. Add a new Synchronize expression between Review Task and Set State Resolved.
3. Update the new Synchronize expression to synchronize on an “Object Event”. Select either the “PARENT CHANGE OBJECT STATE CHANGE” or “CHILD CHANGE OBJECT STATE CHANGE” event. See Solution for descriptions of each event. Add one of the following two expressions in the Initial Expression and Routing Expression:
When listening for “PARENT CHANGE OBJECT STATE CHANGE”:
if(com.ptc.windchill.pdmlink.change.server.impl.WorkflowProcessHelper.
isRelatedParentsInStates (primaryBusinessObject,
new String[]{"RESOLVED"})) {
result = "Resolved";
}
When listening for “CHILD CHANGE OBJECT STATE CHANGE”:
if(com.ptc.windchill.pdmlink.change.server.impl.WorkflowProcessHelper.
isRelatedChildrenInStates(primaryBusinessObject,
new String[]{"RESOLVED"})) {
result = "Resolved";
}
Note that the role A of the change object relationship is considered to be the parent and the role B is the child object.
4. Add a new Expression between Synchronize and Set State Resolved. Set its name to “Set Resolution Date”.
5. Update “Set Resolution Date” to set the resolution date on the change object.
com.ptc.windchill.pdmlink.change.server.impl.WorkflowProcessHelper.
setResolutionDate(primaryBusinessObject);
6. If force closure is required for the change process a new Expression can be added after “Set State Resolved” to close either the parent or child associations. The following is an example expression implementation which forces the associated parent change objects to close in the Resolved state.
java.util.Map<java.lang.Class, wt.lifecycle.State> parentStateMap = new
java.util.HashMap<java.lang.Class, wt.lifecycle.State>(1);
parentStateMap.put(wt.change2.FlexibleChangeItem.class,
wt.lifecycle.State.toState("RESOLVED"));
com.ptc.windchill.pdmlink.change.server.impl.WorkflowProcessHelper.
closeChangeParents(primaryBusinessObject, parentStateMap);