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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

How to get last version by code

VasiliyRepecki
12-Amethyst

How to get last version by code

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.

ACCEPTED SOLUTION

Accepted Solutions

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;

}

View solution in original post

3 REPLIES 3

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;

}

Announcements


Top Tags