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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

How to search multiple WTDocument numbers through WC API

ptc-4576665
1-Visitor

How to search multiple WTDocument numbers through WC API

Hi,

I am trying to find multiple document numbers through WC API.

If I use only one part number in below code, it works fine. If I use search string like "65832A00.*;1234.*" it won't return anything.

qs = new QuerySpec(wtDocCls);

SearchCondition sc = new SearchCondition(WTDocument.class, WTDocument.NUMBER, SearchCondition.LIKE, "65832A00.*;1234.*");

qs.appendWhere(sc);

qr = PersistenceHelper.manager.find(qs);

How can I search multiple documents using API?

5 REPLIES 5
ybagul
12-Amethyst
(To:ptc-4576665)

Try following (with modification for WTDoc).

final QuerySpec querySpec = new QuerySpec(WTPart.class);

querySpec.appendWhere(new SearchCondition(WTPart.class, WTPart.NUMBER, SearchCondition.LIKE, desiredPartNumber.replace('*', '%')), null);

final QueryResult partQueryResult = PersistenceHelper.manager.find((StatementSpec)querySpec);

OK. I am now using "65832A00.%;1234.%". That also do not work. I think I need to use qs.appendOr();

Below code works. But I have query string which contains 10 or more docs. I am thinking of appending Or condition in a loop. It seems that we can not directly use query string in code.

qs = new QuerySpec(wtDocCls);

SearchCondition sc = new SearchCondition(WTDocument.class, WTDocument.NUMBER, SearchCondition.LIKE, "1234%");

qs.appendWhere(sc);

qs.appendOr();

SearchCondition sc1 = new SearchCondition(WTDocument.class, WTDocument.NUMBER, SearchCondition.LIKE, "65832A00.%");

qs.appendWhere(sc1);

qr = PersistenceHelper.manager.find(qs);

You can concat you query results. For example:

qs = new QuerySpec(wtDocCls);

SearchCondition sc = new SearchCondition(WTDocument.class, WTDocument.NUMBER, SearchCondition.LIKE, "1234%");

qs.appendWhere(sc);

qr1 = PersistenceHelper.manager.find(qs);

SearchCondition sc1 = new SearchCondition(WTDocument.class, WTDocument.NUMBER, SearchCondition.LIKE, "65832A00.%");

qr2 = PersistenceHelper.manager.find(qs1);

qr2.append(qr1.method);

* check the method. It must be like "toObjectVector", don't remember...

qr.appendObjectVector(qr1.getObjectVector());

It adds result of qr1 to qr. It works.

But I have 10+ different parts to search like that. executing PersistenceHelper.manager.find so many times and keep adding result might not be that efficient. Is there a way I can build(using appendWhere,appendOr something like that..) query and excecute it only once to get result?

Thanks for your reply. I have now workaround but I am still looking to build a query. Is it possible?

Try to find this solution in the windchill search. Windchill search provide multiple object search with a lot of searching strings for the attributes.

Announcements


Top Tags