Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
Hi! I qant to query object through windchill api like this:
QuerySpec qs = new QuerySpec(WTDocument.class);
qs.setAdvancedQueryEnabled(true);
int ind = qs.appendClassList(WTDocument.class,true);
SearchCondition sc = new SearchCondition(WTDocument.class, WTDocument.NUMBER, SearchCondition.LIKE, "173.157.%");
SearchCondition sc2 = new SearchCondition(WTDocument.class, WTDocument.FOLDERING_INFO, SearchCondition.LIKE, "folderName");
qs.appendWhere(sc, new int[ind]);
qs.appendAnd();
qs.appendWhere(sc2, new int[ind]);
QueryResult qr = PersistenceHelper.manager.find(qs);
while (qr.hasMoreElements())
{
WTDocument doc = (WTDocument)qr.nextElement();
System.out.println(doc.getNumber());
}
But I have an exception that attribute "folderingInfo" is not the member of the wt.doc.WTDocument class.
Whats wrong? How can I create the complex query with a lot of searchConditions?
Solved! Go to Solution.
Hi Anton.
You are hetting the error cause the folder name doesn't store into WTDocument table.
If you want to search any WTDocument based on folder name as well as number try below code.
private static void getByFolderName(String number,String folderName) throws WTException {
QuerySpec queryspec = new QuerySpec(WTDocument.class);
queryspec.setAdvancedQueryEnabled(true);
int typeIndex = queryspec.appendClassList(SubFolder.class, false);
SearchCondition sc1 = new SearchCondition(WTDocument.class,
"folderingInfo.parentFolder.key.id", SubFolder.class,
"thePersistInfo.theObjectIdentifier.id");
queryspec.appendWhere(sc1, new int[] { 0, typeIndex });
queryspec.appendAnd();
queryspec.appendOpenParen();
SearchCondition scSWfd = new SearchCondition(SubFolder.class,
SubFolder.NAME, SearchCondition.LIKE,
folderName, true);
queryspec.appendWhere(scSWfd, new int[] { typeIndex });
queryspec.appendCloseParen();
queryspec.appendAnd();
SearchCondition scSWDoc = new SearchCondition(WTDocument.class,
WTDocument.NUMBER, SearchCondition.LIKE,
number, true);
queryspec.appendWhere(scSWDoc,new int[]{0});
QueryResult queryResult = PersistenceHelper.manager
.find((StatementSpec) queryspec);
System.out.println("Size :- " + queryResult.size());
Persistable[] pt = null;
while (queryResult.hasMoreElements()) {
pt = (Persistable[]) queryResult.nextElement();
for (Persistable per : pt) {
WTDocument doc = (WTDocument) per;
System.out.println(doc.getName());
}
}
}
Thanks,
Kaushik
Hi Anton.
You are hetting the error cause the folder name doesn't store into WTDocument table.
If you want to search any WTDocument based on folder name as well as number try below code.
private static void getByFolderName(String number,String folderName) throws WTException {
QuerySpec queryspec = new QuerySpec(WTDocument.class);
queryspec.setAdvancedQueryEnabled(true);
int typeIndex = queryspec.appendClassList(SubFolder.class, false);
SearchCondition sc1 = new SearchCondition(WTDocument.class,
"folderingInfo.parentFolder.key.id", SubFolder.class,
"thePersistInfo.theObjectIdentifier.id");
queryspec.appendWhere(sc1, new int[] { 0, typeIndex });
queryspec.appendAnd();
queryspec.appendOpenParen();
SearchCondition scSWfd = new SearchCondition(SubFolder.class,
SubFolder.NAME, SearchCondition.LIKE,
folderName, true);
queryspec.appendWhere(scSWfd, new int[] { typeIndex });
queryspec.appendCloseParen();
queryspec.appendAnd();
SearchCondition scSWDoc = new SearchCondition(WTDocument.class,
WTDocument.NUMBER, SearchCondition.LIKE,
number, true);
queryspec.appendWhere(scSWDoc,new int[]{0});
QueryResult queryResult = PersistenceHelper.manager
.find((StatementSpec) queryspec);
System.out.println("Size :- " + queryResult.size());
Persistable[] pt = null;
while (queryResult.hasMoreElements()) {
pt = (Persistable[]) queryResult.nextElement();
for (Persistable per : pt) {
WTDocument doc = (WTDocument) per;
System.out.println(doc.getName());
}
}
}
Thanks,
Kaushik
Hi Kaushik! Thanks a lot! Do you know good manual about querys through windchill api?
Hi Anton,
I never found a good manual regarding this however I can give you couple of more example.
Regards,
Kaushik
Thanks a lot!