How to handle advance queries on Windchill QuerySpecs ?

How to handle advance queries on Windchill QuerySpecs ?

Add Comment
1 Answer(s)

 

 

String parentPartNumber;
String ParentPartName;
String partNumber;
String PartName;

QuerySpec spec = new QuerySpec();

spec.setAdvancedQueryEnabled(true);

int WTPartMasterIndex = spec.addClassList(wt.part.WTPartMaster.class, true);

int WTPartUsageLinkIndex = spec.addClassList(wt.part.WTPartUsageLink.class, true);

int partIndex = spec.appendClassList(wt.part.WTPart.class, true);

SearchCondition where = new SearchCondition(new ClassAttribute(wt.part.WTPartMaster.class,
  "thePersistInfo.theObjectIdentifier.id"), SearchCondition.EQUAL,
 new ClassAttribute(wt.part.WTPartUsageLink.class, "roleBObjectRef.key.id"));

spec.appendWhere(where, new int[] {
 WTPartMasterIndex,
 WTPartUsageLinkIndex
});

spec.appendAnd();

SearchCondition where2 = new SearchCondition(new ClassAttribute(wt.part.WTPartUsageLink.class,
  "roleAObjectRef.key.id"), SearchCondition.EQUAL,
 new ClassAttribute(wt.part.WTPart.class, "thePersistInfo.theObjectIdentifier.id"));

spec.appendWhere(where2, new int[] {
 WTPartUsageLinkIndex,
 partIndex
});

spec.appendAnd();

spec.appendWhere(new SearchCondition(wt.part.WTPart.class, "checkoutInfo.state", SearchCondition.NOT_EQUAL, "wrk"), partIndex);
spec.appendAnd();
spec.appendWhere(new SearchCondition(wt.part.WTPart.class, "iterationInfo.latest", "TRUE"), partIndex);
spec.appendAnd();
spec.appendWhere(new SearchCondition(wt.part.WTPart.class, wt.part.WTPart.LIFE_CYCLE_STATE, SearchCondition.NOT_EQUAL, "CANCELLED"), partIndex);
if (parentPartNumber != null && parentPartNumber.trim().length() != 0) {
 spec.appendAnd();
 spec.appendWhere(new SearchCondition(wt.part.WTPart.class,
  "master>number", SearchCondition.LIKE, parentPartNumber + "%"), partIndex);
}

if (ParentPartName != null && ParentPartName.trim().length() != 0) {
 spec.appendAnd();
 spec.appendWhere(new SearchCondition(wt.part.WTPart.class,
  "master>name", SearchCondition.LIKE, ParentPartName + "%"), partIndex);
}

if (partNumber != null && partNumber.trim().length() != 0) {
 spec.appendAnd();
 spec.appendWhere(new SearchCondition(wt.part.WTPartMaster.class,
  "number", SearchCondition.LIKE, partNumber + "%"), WTPartMasterIndex);
}

if (PartName != null && PartName.trim().length() != 0) {
 spec.appendAnd();
 spec.appendWhere(new SearchCondition(wt.part.WTPartMaster.class,
  "name", SearchCondition.LIKE, PartName + "%"), WTPartMasterIndex);

}
QueryResult result = PersistenceHelper.manager.find(spec);
while (result.hasMoreElements()) {
 wt.fc.Persistable persistables[] = (wt.fc.Persistable[]) result.nextElement();
 wt.part.WTPart parentPart = (wt.part.WTPart) persistables[partIndex];
 wt.part.WTPartUsageLink usageLink = (wt.part.WTPartUsageLink) persistables[WTPartUsageLinkIndex];
 wt.part.WTPartMaster subPartMaster = (wt.part.WTPartMaster) persistables[WTPartMasterIndex];
}

 

Answered on February 10, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.