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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

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

CHASEONHO
18-Opal

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

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

ACCEPTED SOLUTION

Accepted Solutions

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

 

 

 

View solution in original post

6 REPLIES 6

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

Sélection_043.png

 

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!!

Announcements

Top Tags