cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Translate the entire conversation x

QuerySpec to retrieve the documents using latest modified date

LT_12699133
10-Marble

QuerySpec to retrieve the documents using latest modified date

 


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);

 

2 REPLIES 2

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.

 

Announcements
Top Tags