Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
Hi.
How can i get last version of document (WTDocument or EPMDocument) by java code.
For example for A.2 version get latest, which is B.1 ?
Thanks.
Solved! Go to Solution.
i'm using next code:
public static Object getLatestByConfigSpec(Mastered mastered, Iterated iterated) throws WTException
{
Object tempObject = null;
Object resultObject = null;
long id = 0;
QueryResult cQueryResult = ConfigHelper.service.filteredIterationsOf(mastered, ConfigHelper.service.getConfigSpecFor(iterated));
while(cQueryResult.hasMoreElements())
{
tempObject = cQueryResult.nextElement();
if(PersistenceHelper.getObjectIdentifier((Persistable) tempObject).getId() > id)
{
id = PersistenceHelper.getObjectIdentifier((Persistable) tempObject).getId();
resultObject = tempObject;
}
}
return resultObject;
}
Following is one out of many ways of getting this.
public Iterated getLatestObjVersion(final Mastered master) throws WTException, WTPropertyVetoException {
final QueryResult queryResult = VersionControlHelper.service.allVersionsOf(master);
if (!queryResult.hasMoreElements()) {
return null;
}
return (Iterated) queryResult.nextElement();
}
Note: Use myepmDoc.getMaster() or mywtDoc.getMaster() to get Mastered object
Hi Vasiliy. I guess this code will helpfull for you.
public WTDocument getWTDocByNumber(String number)
{
WTDocument wtd = new WTDocument();
WTDocumentMaster wtdm = null;
try
{
QuerySpec qs = new QuerySpec(WTDocumentMaster.class);
qs.appendWhere(new SearchCondition(WTDocumentMaster.class, "number", "=", number), 0);
QueryResult find = PersistenceHelper.manager.find(qs);
if (find.hasMoreElements())
{
wtdm = (WTDocumentMaster)find.nextElement();
}
try {
wtd.setMaster((Mastered)wtdm);
} catch (WTPropertyVetoException ex) {System.out.println(ex);}
}
catch (WTException ex)
{
ex.printStackTrace();
}
return wtd;
}
i'm using next code:
public static Object getLatestByConfigSpec(Mastered mastered, Iterated iterated) throws WTException
{
Object tempObject = null;
Object resultObject = null;
long id = 0;
QueryResult cQueryResult = ConfigHelper.service.filteredIterationsOf(mastered, ConfigHelper.service.getConfigSpecFor(iterated));
while(cQueryResult.hasMoreElements())
{
tempObject = cQueryResult.nextElement();
if(PersistenceHelper.getObjectIdentifier((Persistable) tempObject).getId() > id)
{
id = PersistenceHelper.getObjectIdentifier((Persistable) tempObject).getId();
resultObject = tempObject;
}
}
return resultObject;
}