Skip to main content
18-Opal
November 22, 2017
Solved

Query to get all the available object types within a selected context in Windchill

  • November 22, 2017
  • 1 reply
  • 5768 views

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.

Spoiler
wt.util.WTException: java.lang.ClassCastException: wt.part.WTPart can not be cast to wt.doc.WTDocument
Nested exception: java.lang.ClassCastException: wt.part.WTPart can not be cast to wt.doc.WTDocument
Nested exception: wt.util.WTException: java.lang.ClassCastException: wt.part.WTPart can not be cast to wt.doc.WTDocument
Nested exception: java.lang.ClassCastException: wt.part.WTPart can not be cast to wt.doc.WTDocument
wt.workflow.engine.FailedExpressionException: wt.util.WTException: java.lang.ClassCastException: wt.part.WTPart can not be cast to wt.doc.WTDocument

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

Best answer by olivierfresse

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

 

 

 

1 reply

15-Moonstone
November 22, 2017

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

 

 

 

CHASEONHO18-OpalAuthor
18-Opal
November 23, 2017

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 ()?

15-Moonstone
November 23, 2017

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

Sélection_043.png

 

and you can find lots of code sample in PTC  support site.