Skip to main content
17-Peridot
April 28, 2023
Solved

How do I get all promotion requests in JAVA?

  • April 28, 2023
  • 3 replies
  • 3139 views

Hello everyone
I want to get all the promotion requests that have been approved for this month
I need this to create a custom report that will display WTPart + the number of details it contains;
WTDocument and EPMDocument for which I will get the format and number of sheets from the representation

But I do not know how to get all requests in java

Best answer by VladiSlav
 public static QueryResult getPromotionRequests(DateRange dateRange) throws WTException {
 String startDateStr = dateRange.getDateFromStr();
 String endDateStr = dateRange.getDateToStr();

 QuerySpec querySpec = new QuerySpec(PromotionNotice.class);

 String createStampAttrName = "thePersistInfo.modifyStamp";
 Timestamp startDate = new Timestamp(Date.valueOf(startDateStr).getTime());
 Timestamp endDate = new Timestamp(Date.valueOf(endDateStr).getTime());

 SearchCondition startDateCondition = new SearchCondition(PromotionNotice.class, createStampAttrName, SearchCondition.GREATER_THAN_OR_EQUAL, startDate);
 querySpec.appendWhere(startDateCondition, new int[]{0});

 SearchCondition endDateCondition = new SearchCondition(PromotionNotice.class, createStampAttrName, SearchCondition.LESS_THAN, endDate);
 querySpec.appendAnd();
 querySpec.appendWhere(endDateCondition, new int[]{0});

 SearchCondition approvedStateCondition = new SearchCondition(PromotionNotice.class, "state.state", SearchCondition.EQUAL, "APPROVED");
 querySpec.appendAnd();
 querySpec.appendWhere(approvedStateCondition, new int[]{0});

 return PersistenceHelper.manager.find(querySpec);
 }

3 replies

VladiSlav17-PeridotAuthor
17-Peridot
April 28, 2023

I found the following code that receives all requests. Now it is not possible to get with the condition on the date

QuerySpec qs = new QuerySpec(PromotionNotice.class);
QueryResult qr = PersistenceHelper.manager.find(qs);

while (qr.hasMoreElements()) {
 PromotionNotice pn = (PromotionNotice) qr.nextElement();
 // Do something with the PromotionNotice
}
jbailey
18-Opal
April 28, 2023

Could you provide a little more detail on what you are trying to report on?

avillanueva
23-Emerald I
23-Emerald I
April 28, 2023

Any reason you need it in Java? This seems easier to do in Query Builder. From there you can download straight to Excel, Java or some other application with a web call.

VladiSlav17-PeridotAuthor
17-Peridot
May 1, 2023

 

I need to retrieve all promotion requests that have been approved this month. Query Builder doesn't work for me because I also need to retrieve all components, documents, and drawings from each request. For each document and drawing, I need to retrieve the page format and the number of pages, which can only be done in Java. Can I use Java in Query Builder to count pages?

avillanueva
23-Emerald I
23-Emerald I
May 1, 2023

I know that the first hurdle will be creating a report that includes different object types. In the past, I have created 3 queries to get Parts, Docs and CAD Docs then joined them together with a union (documented on the community site). Not sure about page format but in our case, we looked for the associated Creo format linked to the drawing and pulled from that. I am not sure how you would get the page count but you are right that it might be Java? Are you reading the actually binary content? That might be very slow. Suggest combining efforts. Use a query builder to quickly get the data then pipe into your functions to retrieve the rest of the data.