Community Tip - You can change your system assigned username to something more personal in your community settings. X
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);
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());
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.
@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)
@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!
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.
At Windchill 12.1.1.0 the find(QuerySpec) has been deprecated...
Back to casting to StatementSpec.
Sigh...
Deprecated or totally removed?
So is this correct too?
sc = new SearchCondition(WTChangeOrder2.class, WTChangeOrder2.RESOLUTION_DATE, SearchCondition.IS_NULL);
I don’t have access to Windchill this moment so I can’t answer definitely.
I can tell you,, because I do a lot of this, I wrote a utility which runs in Windchill shell where you enter the class name (wt.change2.WTChangerOrder2 for example and the utility returns all values for each column in the corresponding dB table that can be used in a SearchCondition.
works great and I’ve been using it since Windchill 10.1.. After I wrote it I said to myself, why didn’t I write this utility years ago 😂
@avillanueva wrote:
So is this correct too?
sc = new SearchCondition(WTChangeOrder2.class, WTChangeOrder2.RESOLUTION_DATE, SearchCondition.IS_NULL);
According to InfoReport.sh the resolutionDate column is searched by the string "resolutionDate" so I would say that is correct using WTChangeOrder2.RESOLUTION_DATE.