Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
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
Solved! Go to Solution.
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;
}
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):
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.
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
Yout can reuse the query which I have posted in
Re: SQL Query for document Context/Location
Thanks
Binesh
Barry Wehmiller
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;
}
Thanks, Bhushan, Binesh and Bob for your help ad support.
Regards,
Vivek
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';