Skip to main content
1-Visitor
July 30, 2015
Solved

How to Build a search condition which gives folders name from particular product

  • July 30, 2015
  • 3 replies
  • 3256 views

Hi All,

I have a small piece of code, which returns me list of folders present in Windchill db.

here is my search condition,

SearchCondition sc= new SearchCondition(SubFolder.class,SubFolder.NAME,SearchCondition.EQUAL,FolderName,true);

Input of Program >>  FolderName.

if in Windchill FolderName "abcd" is created under two product, i.e. Product A and Product B.

then it gives me result of "abcd" folder from both products.

i want to add some criteria in search condition for particular product, so it gives me folder names of particular products.

select folder name "abcd" where product is "Product B".

Please suggest.

Regards,

Vivek

Best answer by BhushanNehe

Following should be more efficient way. We are basically creating the following query through code

SELECT A0.*

FROM wt.folder.Folder A0

WHERE (UPPER(A0.name) = 'XXFolderNameXX') AND (A0.idA3containerReference = XXContainerIDXX)

joins=null

Code:

public static Folder findFolder(WTContainer container, String folderName) throws WTException {

  Folder folder = null;

  QuerySpec qs = new QuerySpec (Folder.class);

  qs.setAdvancedQueryEnabled (true);

  qs.appendWhere (new SearchCondition (SubFolder.class, SubFolder.NAME, SearchCondition.LIKE, folderName, false));

  WTContainerRef[] refs = new WTContainerRef[1];

  refs[0]= WTContainerRef.newWTContainerRef(container);

  WhereExpression whereExp1 = WTContainerHelper.getWhereContainerIn (refs);

  qs.appendAnd();

  qs.appendWhere (whereExp1);

  QueryResult qr = PersistenceHelper.manager.find (qs);

  while (qr.hasMoreElements()) {

  SubFolder object = (SubFolder) qr.nextElement();

  System.out.println("Name :  "+object.getName() + "   location: " +object.getFolderPath());

  }

  return folder;

  }

3 replies

1-Visitor
July 30, 2015

If you're getting this information from the Windchill DB, you can have your program essentially do this (assuming the folders both exist at the \Default folder level within their respective products):

  1. Given the name of "Product B" ...
  2. Search the DB for product with name "Product B" and return the ida2a2 value
  3. For a folder that is in "Product B", the ida3b2folderinginfo value will equal the ida2a2 value you got from Step 2.
  4. Since you supply folder name "abcd" and now you also have the ida3b2folderinginfo value (and thus the product ida2a2), you now have the specific folder you are looking for between multiple products.

You can also extend this example in case you have two folders called "abcd" within the same product, but underneath different subfolders.  In this case, the ida3b2folderinginfo value will return the ida2a2 of the folder that "abcd" is in, which you could then get THAT folder's ida3b2folderinginfo etc, etc to get up to the context ida2a2 value.

16-Pearl
July 30, 2015

Hi Vivek,

If there aren't many folders a quick way would be to use FolderHelper.service.findSubFolders in a particular context and match with the given folder name.

public static Folder findOrCreateFolder(WTContainer container, String folderName) throws WTException {

         Folder folder = null;

         // first try to find the folder

         Cabinet cabinet = container.getDefaultCabinet();

         QueryResult qr = FolderHelper.service.findSubFolders(cabinet);

         while (qr.hasMoreElements()) {

             SubFolder subFolder = (SubFolder)qr.nextElement();

             if (subFolder.getName().equals(folderName)) {

                 folder = subFolder;

             }

         }

          // if the folder is null, there is no such folder , then create the folder if it does not exist

         if (folder == null) {

             String path = cabinet.getFolderPath() +"/" + folderName;

             folder = FolderHelper.service.createSubFolder(path, cabinet.getContainerReference());

         }

         return folder;

     }

Regards,

Bhushan

1-Visitor
July 30, 2015

Yout can reuse the query which I have posted in

Re: SQL Query for document Context/Location

Thanks

Binesh

Barry Wehmiller

16-Pearl
July 30, 2015

Following should be more efficient way. We are basically creating the following query through code

SELECT A0.*

FROM wt.folder.Folder A0

WHERE (UPPER(A0.name) = 'XXFolderNameXX') AND (A0.idA3containerReference = XXContainerIDXX)

joins=null

Code:

public static Folder findFolder(WTContainer container, String folderName) throws WTException {

  Folder folder = null;

  QuerySpec qs = new QuerySpec (Folder.class);

  qs.setAdvancedQueryEnabled (true);

  qs.appendWhere (new SearchCondition (SubFolder.class, SubFolder.NAME, SearchCondition.LIKE, folderName, false));

  WTContainerRef[] refs = new WTContainerRef[1];

  refs[0]= WTContainerRef.newWTContainerRef(container);

  WhereExpression whereExp1 = WTContainerHelper.getWhereContainerIn (refs);

  qs.appendAnd();

  qs.appendWhere (whereExp1);

  QueryResult qr = PersistenceHelper.manager.find (qs);

  while (qr.hasMoreElements()) {

  SubFolder object = (SubFolder) qr.nextElement();

  System.out.println("Name :  "+object.getName() + "   location: " +object.getFolderPath());

  }

  return folder;

  }

vuchekar1-VisitorAuthor
1-Visitor
August 5, 2015

Thanks,  Bhushan, Binesh and Bob for your help ad support.

Regards,

Vivek

1-Visitor
February 12, 2016

hi you can use this query to search the folder in a product context

select prd.NAMECONTAINERINFO as "Product Name", sf.NAME from PDMLINKPRODUCT prd, SUBFOLDER sf, CABINET cab

where prd.IDA3C2CONTAINERINFO = cab.IDA2A2 and sf.IDA3A2FOLDERINGINFO = cab.IDA2A2 and prd.NAMECONTAINERINFO = 'test_product';