Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Version: Windchill 12.1
Use Case: need to trigger/initiate a workflow based on a custom action event.
Description:
I have a scenario wherein we need to trigger a workflow upon an action click and inturn that needs to get assigned to the initiator.
need help.
<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);
}
}
thanks!
will try of wtdocument and update here.
also wanted to know if i can delete a CAD template from backend. like i have a querspec code to find it, but need to know if i can delete them.
Hi,
An easy way is to allow a "Set State" action for that type of windchill object.
Catch that transition in the Lifecycle Template and hook a Workflow to that.
In this approach, there is no code and everything is OOTB + Configuration.
Eg:
Initial State : WIP
User sets to the state " For Review"
LC template is configured to trigger workflow at the "GATE" of the LC State "For Review".
Cheers
Hari
in this case im not transitioning a state..lets say my object has a state and from a custom action i need to trigger a work flow which inturn gets initiated to the initiator and gives a task for approval
Adding workflows to normal object state transitions can produce lots of workflow instances. Be careful. Most have opt'd to use this on initial states of change objects.
We have an action that does just this. @Daniel_Ada sample appear the right approach. Ours is the requesting access to a context and appears on the quick links. I am not the original author but I can see the framework is similar. Define you action and custom class. The class will start your workflow with given templates and inputs.