<objecttype class="wt.part.WTPart"
name="xxx"
resourceBundle="xxxxRB">
<action name="xxxx">
<command
class="class Path"
method="custStartProcess"
onClick="JCAConfirm(event,'xxxRB.PRPCESS_START')" />
<includeFilter name="xxxFilter" />
</action>
</objecttype>
public static FormResult custStartProcess(NmCommandBean commanBean) throws WTException, WTPropertyVetoException {
FormResult result = new FormResult();
NmOid primaryOid = commanBean.getActionOid();
Object per = primaryOid.getRefObject();
if (per instanceof WTPart) {
WTPart part = (WTPart) per;
WfProcess process = null;
if (WorkInProgressHelper.isCheckedOut((Workable) part)) {
throw new WTException("Please check in first");
}
QueryResult qrProcs = WfEngineHelper.service.getAssociatedProcesses(part, WfState.OPEN_RUNNING, null);
while (qrProcs.hasMoreElements()) {
process = (WfProcess) qrProcs.nextElement();
if ("xxxx".equals(process.getName())) {// xxxx WorkFlowTemaplateName
if (WfState.OPEN_RUNNING.equals(process.getState())) {
throw new WTException("There is a process that has been started for the current object");
}
}
}
startProcess(part, "xxxx");
FeedbackMessage msg = new FeedbackMessage(FeedbackType.SUCCESS, Locale.ENGLISH, "Start Process", null,
"Start Process Success");
msg.addOidIdentityPair(part, Locale.ENGLISH);
result.addFeedbackMessage(msg);
result.setStatus(FormProcessingStatus.SUCCESS);
}
return result;
}
private static void startProcess(WTObject object, String workFlowName) throws WTException, WTPropertyVetoException {
if (object instanceof WTPart) {
WTPart part = (WTPart) object;
WTContainerRef wtContainerRef = part.getContainerReference();
TeamReference teamReference = part.getTeamId();
WfProcessDefinition processDefinition = WfDefinerHelper.service.getProcessDefinition(workFlowName,
wtContainerRef);
WfProcess wfprocess = WfEngineHelper.service.createProcess(processDefinition, teamReference,
wtContainerRef);
WTPrincipal principal = SessionHelper.manager.getPrincipal();
WTPrincipalReference reference = WTPrincipalReference.newWTPrincipalReference(principal);
wfprocess.setCreator(reference);
ProcessData processData = wfprocess.getContext();
processData.setValue("primaryBusinessObject", part);
WfEngineHelper.service.startProcessImmediate(wfprocess, processData, 0);
}
}