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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

API to kickoff workflows?

MartyRoss
1-Newbie

API to kickoff workflows?

Anyone have & can share some snippets about how to programmatically start a workflow (i.e., via Java or SOAP?)


I see the Start-Workflow webject (and /com/ptc/windchill/ws/StartWorkflow.xml task), and the Java StandardWorkflowService API,but am not yet up to speed on workflows (templates, workflow objects, priority, etc.), so any practical example(s) would really help.


Thanks for any advice and/or examples!


-- Marty


8 REPLIES 8

Hi

Workflow can be initiated by binding the workflow with one of the states of
the lifecycle template. Setting the object's lifecycle state to that
specific state is the easiest way of initiating the workflow. If this is not
meeting your requirement, the workflow can be initiated using Windchill
APIs. Can you briefly explain the requirement so that appropriate solution
can be recommended.







Thank you and have a great time.

Best Regards

Swamy Senthil

Principal Solutions Architect, Swasen Inc

swamy.senthil@swasen.com(Email); 909 800 8423(M); 973 324 2729(W); 866
908 6561(F);






Thanks for the tip!


Clarifying the business requirement, it seems that we want to create a change request, which if I understand correctly will kick off the workflow.


Can you (anyone?) suggest the highest-level, easiest to use and/or most troublefree API thatwe might use to develop a SOAP webservice that can be used by an external agent to create a change request in Windchill?


Would a (SOAPified) task to call the "Create-Object" webject do the trick, and/or be the best way to go for this?

Update: in fact, it's a Change Notice -


Marty,

Here's some code I've got that does this using the attached webject task:


public static WTChangeOrder2 createECN(WTChangeRequest2 request, String cnType) {
if(cnType == null) cnType = "wt.change2.WTChangeOrder2";
WTChangeOrder2 retObj = null;
try {
// Set the creator
SessionMgr.setPrincipal(request.getCreator().getName());

Task createECNTask = new Task("/myTasks/createChangeOrder.xml");

Vector processors = new Vector();
processors.add(WTProperties.getLocalProperties().getProperty("wt.federation.ie.VMName"));
createECNTask.setProcessors(processors);

createECNTask.setUsername(request.getCreator().getName());
createECNTask.setParam("title", "CO-" + request.getNumber() + "-" + request.getName() + " Implementation");
createECNTask.setParam("containerObid", " + request.getContainer().getPersistInfo().getObjectIdentifier());
createECNTask.setParam("obid", " + request);
createECNTask.setParam("type", cnType);
createECNTask.invoke();

Group returnGroup = createECNTask.getGroup("changeOrder");
String obid = (String) returnGroup.getAttributeValue(0, "obid");

Persistable pers = BasicWebjectDelegate.getObjectByUfid(obid);
if(pers instanceof WTChangeOrder2) retObj = (WTChangeOrder2) pers;
} catch (WTException e) {
log.error(e.getMessage(), e);
} catch (RemoteException e) {
log.error(e.getMessage(), e);
} catch (IEException e) {
log.error(e.getMessage(), e);
} catch (IOException e) {
log.error(e.getMessage(), e);
}
return retObj;
}

I hope this helps! BTW there's a way to do all this without even using the Webject task. I'm not sure if this will work without the WTChangeRequest2 obect being available - don't ECNs have to belong to an ECR?

-Thomas R. Busch
Sr. Software Developer
Stryker Instruments
(269) 323-7700 x4014
tom.busch@stryker.com<">mailto:tom.busch@stryker.com>

Thanks, Tom!
After studying this a bit, I realize I still need more context /
background about Windchill workflows, and the APIs.
For one, I'm not familiar with the difference between a Change Request and
a Change Notice, and that seems pretty key to the direction I'm headed
now.
Basically, the requirement seems to be this: we want a way for an outside
non-Windchill application to trigger a workflow in PDM, giving enough of a
description in the request to the people participating in the workflow to
run the ACP configurator to create a new variant from a product master.
That sounds more like a "change request" (in the English context), yet
some of the business workflow documentation I've seen shows screenshots of
using Windchill UI's "New Change Notice" menu function for the manual
version of this, from the "Action" menu of the relevant product master.
Looking at the section on workflows in the 9.1 M040 App Developer's Guide,
and in the Javadoc for the package wt.workflow, I see reference to a PTC
document called "Windchill Workflow Tutorial", yet haven't been able to
find it - do you know where I can? Or, can you point me to any additional
references that might help?
Regards,
-- Marty



Marty Ross
Software Development Sr. Advisor
Dell | Services Healthcare
office +1 617 509 2029
martin_ross@dell.com
Harvard Pilgrim Health Care, 93 Worcester Street, Wellesley, MA 02481

Please consider the environment before printing this email.




"Busch, Tom" <tom.busch@stryker.com>
03/11/2011 11:05 AM

To
marty_ross@harvardpilgrim.org, "-"
<->
cc

Subject
RE: [solutions] - RE: API to kickoff workflows?






Marty,

Here?s some code I?ve got that does this using the attached webject task:


public static WTChangeOrder2 createECN(WTChangeRequest2 request,
String cnType) {
if(cnType == null) cnType = "wt.change2.WTChangeOrder2";
WTChangeOrder2 retObj = null;
try {
// Set the creator
SessionMgr.setPrincipal(request.getCreator().getName());

Task createECNTask = new Task(
"/myTasks/createChangeOrder.xml");

Vector processors = new Vector();
processors.add(WTProperties.getLocalProperties
().getProperty("wt.federation.ie.VMName"));
createECNTask.setProcessors(processors);

createECNTask.setUsername(request.getCreator().getName());
createECNTask.setParam("title", "CO-" +
request.getNumber() + "-" + request.getName() + " Implementation");
createECNTask.setParam("containerObid", " +
request.getContainer().getPersistInfo().getObjectIdentifier());
createECNTask.setParam("obid", " + request);
createECNTask.setParam("type", cnType);
createECNTask.invoke();

Group returnGroup = createECNTask.getGroup("changeOrder"
);
String obid = (String) returnGroup.getAttributeValue(0,
"obid");

Persistable pers = BasicWebjectDelegate.getObjectByUfid
(obid);
if(pers instanceof WTChangeOrder2) retObj =
(WTChangeOrder2) pers;
} catch (WTException e) {
log.error(e.getMessage(), e);
} catch (RemoteException e) {
log.error(e.getMessage(), e);
} catch (IEException e) {
log.error(e.getMessage(), e);
} catch (IOException e) {
log.error(e.getMessage(), e);
}
return retObj;
}

I hope this helps! BTW there?s a way to do all this without even using
the Webject task. I?m not sure if this will work without the
WTChangeRequest2 obect being available ? don?t ECNs have to belong to an
ECR?

-Thomas R. Busch
Sr. Software Developer
Stryker Instruments
(269) 323-7700 x4014
tom.busch@stryker.com

OK, so I've studied a bit more, and found a set of objects (with enough of an operational description for me to work with, in the PDMLink 9.1 BusAdminGuide) that might be relevant:



  1. wt.change2.WTAnalysisActivity

  2. wt.change2.WTChangeRequest2

  3. wt.change2.WTChangeOrder2

  4. wt.change2.WTChangeIssue

  5. wt.change2.WTChangeInvestigation

  6. wt.change2.WTChangeProposal

  7. wt.doc.WTDocument

  8. wt.maturity.PromotionNotice

  9. wt.part.WTProductInstance2

  10. wt.change2.WTVariance

  11. com.ptc.wpcfg.doc.VariantSpec

I suppose, depending upon the results of our requirements discovery, any of these (or other) candidate objects could be selected as needing to be created by the target webservice(s). I'm now wondering what's the best way for us to learn how to create these objects programmatically - i.e., what Java API and/or Webject is the best choice, and what input parameter(s) or precursors are needed for each?



In Reply to Marty Ross:


Thanks, Tom!
After studying this a bit, I realize I still need more context /
background about Windchill workflows, and the APIs.
For one, I'm not familiar with the difference between a Change Request and
a Change Notice, and that seems pretty key to the direction I'm headed
now.

We start everything here with a WTChangeRequest2. I think the intent is to start with a problem report or a change proposal, but this seems to work for us. The way it works is we treat the change request as the initial proposal and approval of the change, then we treat the change order (or change notice or change implementation, depending what you're reading and which version of Windchill, but they are all the same thing) as the "implementation" step - where we officially make the change -- update CAD, documentation, etc. The change activity represents a "Change Task" in the "Implementation Plan". Again in quotes because it seems to have changed version-to-version.

So basically the way we do it, here's what it looks like:


· WTChangeRequest2

o WTChangeOrder2

§ WTChangeActivity2

You have the opportunity for one change request to have multiple change orders, and one change order to have multiple change activities.

We don't use the rest of the structure here (proposals, problem reports, etc) so I can't really give you much insight on that part.

As far as creating objects, you can use the same webject task I attached earlier, you just have to modify it to suit your soft type. I've got code for creating change activities that can probably be largely used to create change notices too, if you need it.

Hopefully someone else can pipe in with a little bit more insight on the OOTB change process structure.

-Thomas R. Busch
Sr. Software Developer
Stryker Instruments
(269) 323-7700 x4014
tom.busch@stryker.com<">mailto:tom.busch@stryker.com>

Tom,
Thanks!! That's exactly the sort of advice I was looking for. Now I have
a direction, and some test cases to setup!
Regards,
-- Marty

Marty Ross
Software Development Sr. Advisor
Dell | Services Healthcare
office +1 617 509 2029
martin_ross@dell.com
Harvard Pilgrim Health Care, 93 Worcester Street, Wellesley, MA 02481

Please consider the environment before printing this email.




"Busch, Tom" <tom.busch@stryker.com>
03/14/2011 08:50 AM

To
marty_ross@harvardpilgrim.org, "-"
<->
cc

Subject
RE: [solutions] - RE: API to kickoff workflows?




We start everything here with a WTChangeRequest2. I think the intent is
to start with a problem report or a change proposal, but this seems to
work for us. The way it works is we treat the change request as the
initial proposal and approval of the change, then we treat the change
order (or change notice or change implementation, depending what you?re
reading and which version of Windchill, but they are all the same thing)
as the ?implementation? step ? where we officially make the change --
update CAD, documentation, etc. The change activity represents a ?Change
Task? in the ?Implementation Plan?. Again in quotes because it seems to
have changed version-to-version.

So basically the way we do it, here?s what it looks like:

· WTChangeRequest2
o WTChangeOrder2
§ WTChangeActivity2

You have the opportunity for one change request to have multiple change
orders, and one change order to have multiple change activities.

We don?t use the rest of the structure here (proposals, problem reports,
etc) so I can?t really give you much insight on that part.

As far as creating objects, you can use the same webject task I attached
earlier, you just have to modify it to suit your soft type. I?ve got code
for creating change activities that can probably be largely used to create
change notices too, if you need it.

Hopefully someone else can pipe in with a little bit more insight on the
OOTB change process structure.

-Thomas R. Busch
Sr. Software Developer
Stryker Instruments
(269) 323-7700 x4014
tom.busch@stryker.com



Top Tags