Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Hello,
I would like to display all the objects belongs to a subtype of the WTDocument using the query spec. can you please help me int his. The below code did not help me in this.
Thanks.
QuerySpec qs = new QuerySpec(WCTYPE|wt.doc.WTDocument.class|<MYCUSTOM_TYPE>);
You can do this using the key reference id
first get the reference using:-
TypeDefinitionReference typeDefRef = TypedUtility.getTypeDefinitionReference("<customtype>"));
then put it in qs:-
qs=new QuerySpec( new SearchCondition(WTDocument.class,"typeDefinitionReference.key.id", SearchCondition.EQUAL, typeDefRef.getKey().getId()));
Hi Hrishikesh,
Many thanks for your reply.
I am very new to Windchill customization. custom type is nothing but the internal name ??
I will test it and let you know the result
Hi Hrishikesh,
I am getting the below error
D:\ptc\Windchill_10.2\Windchill\codebase\wt\part\WTPart.class: warning: Cannot f
ind annotation method 'compositeIndex3()' in type 'TableProperties'
TableBuilder.java:125: error: no suitable constructor found for QuerySpec(Search
Condition)
QuerySpec qs = new QuerySpec(new wt.query.SearchCondition(wt.doc
.WTDocument.class,"typeDefinitionReference.key.id", wt.query.SearchCondition.EQU
AL, typeDefRef.getKey().getId()));
^
constructor QuerySpec.QuerySpec(boolean) is not applicable
(actual argument SearchCondition cannot be converted to boolean by method
invocation conversion)
constructor QuerySpec.QuerySpec(Class[]) is not applicable
(actual argument SearchCondition cannot be converted to Class[] by method
invocation conversion)
constructor QuerySpec.QuerySpec(Class,Class,QuerySpec) is not applicable
(actual and formal argument lists differ in length)
constructor QuerySpec.QuerySpec(Class,Class) is not applicable
(actual and formal argument lists differ in length)
constructor QuerySpec.QuerySpec(String) is not applicable
(actual argument SearchCondition cannot be converted to String by method i
nvocation conversion)
constructor QuerySpec.QuerySpec(Class) is not applicable
(actual argument SearchCondition cannot be converted to Class by method in
vocation conversion)
constructor QuerySpec.QuerySpec() is not applicable
(actual and formal argument lists differ in length)
Note: TableBuilder.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
3 errors
100 warnings
And my code looks like
TypeDefinitionReference typeDefRef = TypedUtility.getTypeDefinitionReference("xxx.xx.yy.AdviceAndInstruction");
QuerySpec qs = new QuerySpec(new wt.query.SearchCondition(wt.doc.WTDocument.class,"typeDefinitionReference.key.id", wt.query.SearchCondition.EQUAL, typeDefRef.getKey().getId()));
qs.setQueryLimit(10000);
Hi John,
Your code is working fine at my side.
If it is not working on your side There is one more way that you can use
IdentifierFactory IDENTIFIER_FACTORY = (IdentifierFactory) DefaultServiceProvider.getService(IdentifierFactory.class, "logical");
TypeIdentifier tid = (TypeIdentifier) IDENTIFIER_FACTORY.get("xxx.xx.yy.AdviceAndInstruction");
QuerySpec qs = new QuerySpec();
int idx = qs.addClassList(WTDocument.class, true);
SearchCondition sc = TypedUtilityServiceHelper.service.getSearchCondition(tid, true);
qs.appendWhere(sc, new int[] { idx });
qs.appendAnd();
int index = 0;
qs.appendWhere(new SearchCondition(WTDocument.class,Iterated.LATEST_ITERATION, SearchCondition.IS_TRUE),
new int[] { index });
System.out.println("query3: " + qs);
QueryResult qr = PersistenceHelper.manager.find(qs);
while (qr.hasMoreElements()) {
Persistable[] ar = (Persistable[]) qr.nextElement();
WTDocument doc = (WTDocument) ar[idx];
System.out.println(part
+ " - "
+ doc.getName()
+ " - "
+ TypedUtilityServiceHelper.service
.getExternalTypeIdentifier(doc));
}