The PTC Community is on temporary read only status in preparation for moving our community to a new platform. Learn more here
Description:
Version: Windchill 13.0
Use Case: Fetch all unique WTDocuments of allowed types, modified on or after a given timestamp, across multiple document types, without duplicates.
Description:
I am using below queryspec however it is not returning the results expected, for example when I do teh search in Windchill advance search it fetched results around 300 but using queryspec it is fetching around 60. I am not sure why this discrepency is happening but please help me if you knwo something here.
we can have multiple document type. Also internal name is correct. I have cross checked as well. just fetching few results not entire is confusing me.
List<Long> typeIds = new ArrayList<>();
System.out.println("getWTDocumentByLastModifiedDate allowedDocumentTypes>>> "+allowedDocumentTypes);
QuerySpec qs = new QuerySpec(WTDocument.class);
for (String typeId : allowedDocumentTypes) {
System.out.println("getWTDocumentByLastModifiedDate typeId>>> "+typeId);
TypeDefinitionReference tdRef = TypedUtilityServiceHelper.service.getTypeDefinitionReference(typeId.trim());
typeIds.add(tdRef.getKey().getId());
}
qs.appendOpenParen();
for (int i = 0; i < typeIds.size(); i++) {
if (i > 0) {
qs.appendOr();
}
qs.appendWhere(new SearchCondition(WTDocument.class, "typeDefinitionReference.key.id", SearchCondition.EQUAL, typeIds.get(i)), new int[] { 0 });
}
qs.appendCloseParen();
qs.appendAnd();
qs.appendWhere(new SearchCondition(WTDocument.class, WTDocument.MODIFY_TIMESTAMP, SearchCondition.GREATER_THAN_OR_EQUAL, timestamp), new int[] { 0 });
QueryResult qr = PersistenceHelper.manager.find((StatementSpec)qs);
Also, I just found out one thing that it is skipping parts which have modified date end with EDT and selecting only EST one's
If you print out qs.toString() you should be able to see the query it is executing to verify it looks like you want it to.
Other things to consider....
qs.setDistinct(true);
qs.setDescendantQuery(false); //Explained here https://www.ptc.com/en/support/article/CS456437 I always do this when I'm debugging otherwise it's hard to see exactly what the query is with all the other types.
Hi @LT_12699133,
I wanted to see if you got the help you needed.
If so, please mark the appropriate reply as the Accepted Solution. It will help other members who may have the same question.
Of course, if you have more to share on your issue, please pursue the conversation.
Thanks,
Anurag
