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
Good morning I'm SeonHo
There are some questions about configuring the Promotion Request Approval Process.
We have configured as follows.
wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice)primaryBusinessObject; wt.fc.QueryResult qr= wt.maturity.MaturityHelper.service.getPromotionTargets(pn); while (qr.hasMoreElements()) { wt.doc.WTDocument doc=(wt.doc.WTDocument) qr.nextElement(); wt.lifecycle.LifeCycleServerHelper.service.setState((wt.lifecycle.LifeCycleManaged)doc,wt.lifecycle.State.toState("DESIGNCHANGE")); } try { wt.util.WTProperties props = wt.util.WTProperties.getLocalProperties(); VERBOSE = props.getProperty("wt.maturity.verbose",VERBOSE); } catch( Throwable t ) { } try{ wt.maturity.MaturityServerHelper.service.unlockTargets (pn); } catch (wt.maturity.MaturityException me){ if ( VERBOSE ) me.printStackTrace(); }
As a result, when I rejected it, I succeeded in designing the life cycle by design change.
But it was the case of WTDocument.
For WTParts, an error has occurred.
So I modified the code as follows.
wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice)primaryBusinessObject; wt.fc.QueryResult qr= wt.maturity.MaturityHelper.service.getPromotionTargets(pn); try { while (qr.hasMoreElements()) { wt.doc.WTDocument doc=(wt.doc.WTDocument) qr.nextElement(); wt.lifecycle.LifeCycleServerHelper.service.setState((wt.lifecycle.LifeCycleManaged)doc,wt.lifecycle.State.toState("DESIGNCHANGE")); } }catch(wt.util.WTException e){ wt.part.WTPart pt=(wt.part.WTPart) qr.nextElement(); wt.lifecycle.LifeCycleServerHelper.service.setState((wt.lifecycle.LifeCycleManaged)pt,wt.lifecycle.State.toState("DESIGNCHANGE")); } try { wt.util.WTProperties props = wt.util.WTProperties.getLocalProperties(); VERBOSE = props.getProperty("wt.maturity.verbose",VERBOSE); } catch( Throwable t ) { } try{ wt.maturity.MaturityServerHelper.service.unlockTargets (pn); } catch (wt.maturity.MaturityException me){ if ( VERBOSE ) me.printStackTrace(); }
However, I have also encountered the same error.
In my opinion, i can figure out the type of WTObject and then use switch to specify a specific lifecycle as in the first case for WTDocument.
After that, we follow the origin process for the remainder and return to the state before the promotion.
The code will look roughly like this:
wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice)primaryBusinessObject; wt.fc.QueryResult qr= wt.maturity.MaturityHelper.service.getPromotionTargets(pn); while (qr.hasMoreElements()) { wt.object.type ot = qr.getObjectType ??? switch(ot) { case "WTDocument" : wt.doc.WTDocument doc=(wt.doc.WTDocument) qr.nextElement(); wt.lifecycle.LifeCycleServerHelper.service.setState((wt.lifecycle.LifeCycleManaged)doc,wt.lifecycle.State.toState("DESIGNCHANGE")); break; default : break; } }
Is it wrong?
I would appreciate your feedback.
thank
Solved! Go to Solution.
Hi,
Remember, Windchill's model is object oriented 🙂
Each business object implements interfaces, each interface implements a behavior.
In your case,
wt.ifecycle.LifeCycleManaged
And the service methods signature is
LifeCycleManaged setState(LifeCycleManaged var1, State var2) throws WTException, LifeCycleException;
Therefore, you can use :
wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice) primaryBusinessObject; wt.fc.QueryResult qr = wt.maturity.MaturityHelper.service.getPromotionTargets(pn); while (qr.hasMoreElements()) { wt.lifecycle.LifeCycleManaged lifeCycleManaged = (wt.lifecycle.LifeCycleManaged) qr.nextElement(); wt.lifecycle.LifeCycleServerHelper.service.setState(lifeCycleManaged, wt.lifecycle.State.toState("DESIGNCHANGE")); } try { wt.util.WTProperties props = wt.util.WTProperties.getLocalProperties(); VERBOSE = props.getProperty("wt.maturity.verbose", VERBOSE); } catch (Throwable t) { } try { wt.maturity.MaturityServerHelper.service.unlockTargets(pn); } catch (wt.maturity.MaturityException me) { if (VERBOSE) me.printStackTrace(); }
This code works for all lifeCycle managed objects
Hi,
Remember, Windchill's model is object oriented 🙂
Each business object implements interfaces, each interface implements a behavior.
In your case,
wt.ifecycle.LifeCycleManaged
And the service methods signature is
LifeCycleManaged setState(LifeCycleManaged var1, State var2) throws WTException, LifeCycleException;
Therefore, you can use :
wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice) primaryBusinessObject; wt.fc.QueryResult qr = wt.maturity.MaturityHelper.service.getPromotionTargets(pn); while (qr.hasMoreElements()) { wt.lifecycle.LifeCycleManaged lifeCycleManaged = (wt.lifecycle.LifeCycleManaged) qr.nextElement(); wt.lifecycle.LifeCycleServerHelper.service.setState(lifeCycleManaged, wt.lifecycle.State.toState("DESIGNCHANGE")); } try { wt.util.WTProperties props = wt.util.WTProperties.getLocalProperties(); VERBOSE = props.getProperty("wt.maturity.verbose", VERBOSE); } catch (Throwable t) { } try { wt.maturity.MaturityServerHelper.service.unlockTargets(pn); } catch (wt.maturity.MaturityException me) { if (VERBOSE) me.printStackTrace(); }
This code works for all lifeCycle managed objects
thanks olivierfresse!!
problem has been solved by you.
I would like to learn more about writing code in windchill
How do you write code about the API ...
Can I get tips on writing windchill code please?
In addition, what api should I use to determine if an object's type is a WT document or an EPM document?
wt.fc.WTObject ot = pn wt.fc.WTObject.getDisplayType()
Was the correct way to write code using getDisplayType ()?
Well, first the easy one.
Windchill Objects are java objects, therefore you can get their class name..
WTPart foo = .... // initialized somewhere String className = foo.getClass().getName(); // -> className contains "wt.part.WTPart"
This is pure java.
But PDMLinks provide softtypes... So if you need the logical identifier, you have to use
import wt.type.TypedUtilityServiceHelper WTPart subTypedPart = ... // retrieved from somewhere String subType = TypedUtilityServiceHelper.service.getExternalTypeIdentifier(subTypedPart); // returns WCTYPE|wt.part.WTPart|project.TaskSkillResource
In the example, my subTypedPart is a subtype of WTPart and has a logical id project.TaskSkillResource.
Next, learning PDMLinks api, well, it's a huge task 🙂
But there is quite a lot of documentation : https://support.ptc.com/appserver/cs/doc/refdoc.jsp
and you can find lots of code sample in PTC support site.
Thank you so much.
Thank you for your kind explanation.
I'm sorry, but I'll have one more thing.
Can I use api to determine the type of windchill object to construct a logical identifier?
wt.fc.QueryResult qr = wt.maturity.MaturityHelper.service.getPromotionTargets (pn);
For example, using the above code, it seems to contain information about the object.
TypedUtilityServiceHelper.service.getExternalTypeIdentifier (qr);
Can use the following code to tell qr whether it is part or document?
Hello,
QueryResult is an enumeration, therefore :
wt.fc.QueryResult qr = wt.maturity.MaturityHelper.service.getPromotionTargets (pn);
wt.fc.Persistable persistable;
while(qr.hasMoreElements()){
persistable = qr.nextElement();
// get the type...
TypedUtilityServiceHelper.service.getExternalTypeIdentifier(persistable);
}
Thank you so much!!!
it is be make me greater!!