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

how to write query to get Documents in a particular product?

SOLVED
Level 1

how to write query to get Documents in a particular product?

Hello,

I am new in windchill customization, i am to write a query to get all the documents( say type "x") in a product(say "y"). Can somebody help???

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: how to write query to get Documents in a particular product?

Well, it is returning array, use the following code to get pass the error

QuerySpec queryspec = new QuerySpec(WTDocumentMaster.class);

  queryspec.setAdvancedQueryEnabled(true);

  int contIndex = queryspec.appendClassList(PDMLinkProduct.class,false);

  SearchCondition sc1 = new SearchCondition(WTDocumentMaster.class, "containerReference.key.id",PDMLinkProduct.class, wt.util.WTAttributeNameIfc.ID_NAME);

  queryspec.appendWhere(sc1, new int[] { 0, contIndex });

  queryspec.appendAnd();

  SearchCondition scSWPart = new SearchCondition(PDMLinkProduct.class ,"containerInfo.name",SearchCondition.EQUAL,"TestProduct1",true);

  queryspec.appendWhere(scSWPart,new int[] { contIndex });

  QueryResult queryResult = PersistenceHelper.manager.find(queryspec);

  System.out.println("Size :- " + queryResult.size());

  int size = queryResult.size();

  System.out.println("WTDocument query result size: " + size);

while (queryResult.hasMoreElements()) {

  wt.fc.Persistable persisArray []= (Persistable[]) queryResult.nextElement();

  wt.doc.WTDocumentMaster doc=(WTDocumentMaster) persisArray[0];

  System.out.println(doc);

  }

Regards,

Bhushan

12 REPLIES 12

Re: how to write query to get Documents in a particular product?

Assuming by "query" you mean an SQL query, then you need to join the correct context type DB table (PDMLinkProduct, WTLibrary, or Project2 are the table names) for the table you are trying to get to the wtdocument DB table, and note that for the wtdocument table the ida3containerreference column contains the same value as the context DB table's ida2a2 value.

Out of curiosity, what type of functionality are you looking to customize?  My company is very experienced in all things Windchill and I'd be happy to lend a helping hand or provide additional options to achieve a certain functionality depending upon the need.

Re: how to write query to get Documents in a particular product?

I meant by queryspec.

Re: how to write query to get Documents in a particular product?

Add Context and create a Join with WTDocument, set the Criteria to Context:Name... You can use a Parameter here so that the User can enter the Context Name when performing the query

Re: how to write query to get Documents in a particular product?

Thanks for your reply, Could you please give me queryspec ... ?

Re: how to write query to get Documents in a particular product?

the query i am using is as below, but it's giving exception.

QuerySpec qss = new QuerySpec(WTDocumentMaster.class);

  qss.appendWhere(new SearchCondition(WTDocumentMaster.class,WTDocumentMaster.CONTAINER_NAME,SearchCondition.EQUAL,"TestProduct1"),new int[] { 0 });

exception is saying

Attribute "containerReference.name" is not a member of class "class wt.doc.WTDocumentMaster.

Re: how to write query to get Documents in a particular product?

Hi Gajendra

Following example is for Cad Document, you can modify to use if to WTDocuments

QuerySpec queryspec =

new QuerySpec(EPMDocument.

class);

queryspec.setAdvancedQueryEnabled(

true);

int contIndex = queryspec.appendClassList(PDMLinkProduct.class,false);

SearchCondition sc1 =

new SearchCondition(EPMDocument.class, "containerReference.key.id",PDMLinkProduct.class, wt.util.WTAttributeNameIfc.ID_NAME);

queryspec.appendWhere(sc1,

new int[] { 0, contIndex });

queryspec.appendAnd();

SearchCondition scSWPart =

new SearchCondition(PDMLinkProduct.class ,"containerInfo.name",SearchCondition.EQUAL,"<your product name>",true);

queryspec.appendWhere(scSWPart,

new int[] { contIndex });

QueryResult queryResult = PersistenceHelper.

manager.find((StatementSpec)queryspec);

System.

out.println("Size :- " + queryResult.size());

Regards,

Bhushan

Re: how to write query to get Documents in a particular product?

hello Bhushan,

Thank you for reply,

used modified the query as below,

QuerySpec queryspec = new QuerySpec(WTDocumentMaster.class); 

  queryspec.setAdvancedQueryEnabled(true);   

  int contIndex = queryspec.appendClassList(PDMLinkProduct.class,false); 

  SearchCondition sc1 = new SearchCondition(WTDocumentMaster.class, "containerReference.key.id",PDMLinkProduct.class, wt.util.WTAttributeNameIfc.ID_NAME); 

  queryspec.appendWhere(sc1, new int[] { 0, contIndex }); 

  queryspec.appendAnd(); 

   SearchCondition scSWPart = new SearchCondition(PDMLinkProduct.class ,"containerInfo.name",SearchCondition.EQUAL,"TestProduct1",true); 

  queryspec.appendWhere(scSWPart,new int[] { contIndex }); 

  QueryResult queryResult = PersistenceHelper.manager.find((StatementSpec)queryspec); 

  System.out.println("Size :- " + queryResult.size()); 

  int size = queryResult.size();

  System.out.println("WTDocument query result size: " + size);

  if (logger.isTraceEnabled()) {

  logger.trace("Query Size:" + size);

  }

  while (queryResult.hasMoreElements()) {

  WTDocumentMaster docMstr = (WTDocumentMaster) queryResult

  .nextElement();

  LatestConfigSpec ltSpec = new LatestConfigSpec();

this is throwing exception

Exception in thread "main" wt.util.WTRemoteException: Unable to invoke remote method; nested exception is:

  java.rmi.ServerRuntimeException: Server exception; nested exception is:

  java.lang.ClassCastException: [Lwt.fc.Persistable; cannot be cast to wt.doc.WTDocumentMaster

  at wt.method.RemoteMethodServer.invoke(RemoteMethodServer.java:788)

  at com.comdev.tools.ReassignLCRDDWithContainerInfo.main(ReassignLCRDDWithContainerInfo.java:99)

Caused by: java.lang.ClassCastException: [Lwt.fc.Persistable; cannot be cast to wt.doc.WTDocumentMaster

  ... 2 more

Could you please correct me where i am wrong?

Highlighted

Re: how to write query to get Documents in a particular product?

Gajendra - any reason for passing WTDocumentMaster instead of WTDocument to QuerySpec?

Re: how to write query to get Documents in a particular product?

No, not any specific reason, i found query somewhere so i tried.

My goal is to reassign Life cycle to all the WTDocuments in "TestProduct1" product.