Skip to main content
1-Visitor
January 11, 2016
Solved

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

  • January 11, 2016
  • 1 reply
  • 7642 views

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

Best answer by BhushanNehe

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

1 reply

1-Visitor
January 11, 2016

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.

1-Visitor
January 11, 2016

I meant by queryspec.

1-Visitor
January 11, 2016

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