Skip to main content
avillanueva
23-Emerald I
23-Emerald I
July 17, 2023
Question

Querying Change Notices created by a specific user

  • July 17, 2023
  • 2 replies
  • 3635 views

Looking for the right way to call this. I have the user object passed in and want to search for change notices created by that user that are still active. Do I have the right call? I saw a message that "CREATOR" was ambiguous when compiling. 

QuerySpec spec = new QuerySpec();
			int changeNotice = spec.addClassList(WTChangeOrder2.class, true);
			SearchCondition sc = new SearchCondition(WTChangeOrder2.class,WTChangeOrder2.CREATOR, SearchCondition.EQUAL, user.getDisplayIdentifier());
			spec.appendWhere(sc, new int[] {changeNotice});
			spec.appendAnd();
			sc = new SearchCondition(WTChangeOrder2.class, WTChangeOrder2.RESOLUTION_DATE, SearchCondition.IS_NULL);
			spec.appendWhere(sc, new int[] {changeNotice});
			spec.appendAnd();
			sc = new SearchCondition(WTChangeOrder2.class, WTChangeOrder2.NEED_DATE, SearchCondition.LESS_THAN, timestamp);
			spec.appendWhere(sc, new int[] {changeNotice});
			
			QueryResult lateCN = PersistenceHelper.manager.find((StatementSpec)spec);

 

2 replies

20-Turquoise
July 17, 2023

I would probably change your first search condition to something like this:

SearchCondition sc = new SearchCondition(WTChangeOrder2.class, "creator.key.id", SearchCondition.EQUAL, user.getPersistInfo().getObjectIdentifier().getId());
avillanueva
23-Emerald I
23-Emerald I
July 17, 2023

Thanks. On second search condition, we saw something like this: (wt.query.queryResource/4) wt.query.QueryException: Attribute "resolutionDate" of class "java.sql.Timestamp" is not of type "java.lang.Boolean" which is odd since the value is null and that is what I am looking for.

18-Opal
July 17, 2023

@RandyJones  Is correct.

 

The reason you get ambiguous is WTChangeOrder2.CREATOR as two possibilities, id and classname. Therefore ambiguous.

 

BTW, unless your running your code on Windchill 8.0 (which I doubt) there’s no need to cast a QuerySpec to a StatementSpec. At release 10.0 PTC add .find(QuerySpec)

20-Turquoise
July 17, 2023

@d_graham wrote:

 

BTW, unless your running your code on Windchill 8.0 (which I doubt) there’s no need to cast a QuerySpec to a StatementSpec. At release 10.0 PTC add .find(QuerySpec)


And you are so correct. Old habits die hard...

More code cleanup opportunities!

20-Turquoise
July 17, 2023

And apparently old habits die hard at PTC also! All the "how to" articles I have ever read also cast QuerySpec to StatementSpec including a fairly recent one: CS381551.

Note the earliest version of Windchill it applies to is 11.2 - way after 10.0.