Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

can we trigger a workflow by clicking a custom action?

SK_12337814
5-Regular Member

can we trigger a workflow by clicking a custom action?

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.

ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

9 REPLIES 9

<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);
        }
}
SK_12337814
5-Regular Member
(To:Daniel_Ada)

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.

 

 

SK_12337814
5-Regular Member
(To:Daniel_Ada)

Hi,

 

wanted to understand what this line mean

 

SK_12337814_0-1734346780220.png

 

Hi @SK_12337814 

It is a javaScript method that is called if you click on the button of the page. 

JCAConfigm is a method that shows a confirm message on the page where xxx.RB.... is a key from the rbInfo where the messages are stored. 

PetrH

This line will pop up a confirmation dialog with the prompt word being the value of the xxxRB.PROCESS_START

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

SK_12337814
5-Regular Member
(To:Hari_Vara)

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

avillanueva
22-Sapphire II
(To:Hari_Vara)

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.

avillanueva
22-Sapphire II
(To:SK_12337814)

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. 

Announcements
Top Tags