I have, Here's how. This may not be the only way to do it but it works effectively. You pass in your soft type's logical identifier as the "cnType" parameter.
public static WTChangeOrder2 createECN(WTChangeRequest2 request, String cnType) {
if(cnType == null) cnType = "wt.change2.WTChangeOrder2";
WTChangeOrder2 retObj = null;
try {
// Set the creator
wt.session.SessionMgr.setPrincipal(request.getCreator().getName());
Task createECNTask = new Task("/custom/createChangeOrder.xml");
Vector processors = new Vector();
processors.add(wt.util.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 = DocumentUtility.getObjectFromObid(obid);
if(pers instanceof WTChangeOrder2) retObj = (WTChangeOrder2) pers;
} catch (WTException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (IEException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return retObj;
}
And if you need it, here's DocumentUtility.getObjectFromObid()
public static Persistable getObjectFromObid(String obid) throws WTException {
if (obid.indexOf("@") > -1) {
String[] obidParts = obid.split(":");
if (obidParts.length > 3) {
obid = obidParts[0] + ":" + obidParts[1] + ":" + obidParts[2];
}
}
ReferenceFactory rf = new ReferenceFactory();
WTReference ref = rf.getReference(obid);
return ref.getObject();
}
And finally here's the createChangeOrder.xml task:
<%@page language="java"%>
<%@taglib uri="
prefix="ie"%>
<%
String windchill = wt.util.WTProperties.getLocalProperties().getProperty("wt.federation.ie.VMName");
String title = (String) getContextGroup("FORM").getAttributeValue(0, "title");
String desc = (String) getContextGroup("FORM").getAttributeValue(0, "desc");
String obid = (String) getContextGroup("FORM").getAttributeValue(0, "obid");
String containerObid = (String) getContextGroup("FORM").getAttributeValue(0, "containerObid");
String type = (String) getContextGroup("FORM").getAttributeValue(0, "type");
if(type == null) type = "WTChangeOrder2";
if(desc == null) desc = title;
if(title.length() > 70) title = title.substring(0, 70);
%>
<ie:webject name="Query-Objects" type="OBJ">
<ie:param name="INSTANCE" data="<%=" windchill=" %=">"/>
<ie:param name="ATTRIBUTE" data="name,obid" delim=","/">
<ie:param name="GROUP_OUT" data="container"/">
<ie:param name="OBJECT_REF" data="<%=" containerobid=" %=">" />
<ie:param name="AUTHORIZATION" data="${@server[]authorization[0]}"/">
<ie:param name="TYPE" data="wt.inf.container.WTContainer"/">
<ie:param name="SESSION_ID" data="${session[]SESSION_ID[0]}"/">
</ie:webject>
<ie:webject name="Create-Objects" type="ACT">
<ie:param name="INSTANCE" data="<%=" windchill=" %=">"/>
<ie:param name="ATTRIBUTE" data="name,obid" delim=","/">
<ie:param name="GROUP_OUT" data="changeOrder"/">
<ie:param name="AUTHORIZATION" data="${@server[]authorization[0]}"/">
<ie:param name="TYPE" data="<%=" type=" %=">"/>
<ie:param name="CONTAINER_REF" data="${container[0]obid[0]}"/>
<ie:param name="FIELD" data="name='<%=title" %=">" />
<ie:param name="FIELD" data="description='<%=desc" %=">" />
</ie:webject>
<ie:webject name="Create-Links" type="OBJ">
<ie:param name="INSTANCE" data="<%=" windchill=" %=">"/>
<ie:param name="FROM_OBJECT_REF" data="<%=obid" %=">" />
<ie:param name="GROUP_IN" data="changeOrder"/>
<ie:param name="AUTHORIZATION" data="${@server[]authorization[0]}"/">
<ie:param name="CONTAINER_REF" data="${container[0]obid[0]}"/>
<ie:param name="TYPE" data="wt.change2.AddressedBy2"/">
</ie:webject>
<ie:webject name="Return-Groups" type="GRP">
<ie:param name="GROUP_IN" data="*"/">
</ie:webject>
Now, I'm sure there's a way to do this directly through the API without the webject, but this works effectively without spending a decade trying to understand Windchill's poorly documented API.
-Thomas R. Busch
Sr. Software Developer
Stryker Instruments
(269) 323-7700 x4014
tom.busch@stryker.com<
">mailto:tom.busch@stryker.com>