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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Get programmatically Version History of document

AB_9905442
4-Participant

Get programmatically Version History of document

Hello ,
I want to display some data regarding Version History of document  (WINDCHILL 11) 
version , file name , state , comments ,modified by and last modified 

ptc.png

 

ACCEPTED SOLUTION

Accepted Solutions

Hi @AB_9905442 

btw the VersionControlHelper contains an other method that returns all iterations. allIterationsFrom

 

try
{
	WTDocument document = getDocumentByNumber("0000000142");
	QueryResult allVersions = VersionControlHelper.service.allIterationsFrom(document);
	while (allVersions.hasMoreElements())
	{
		Object obj = allVersions.nextElement();
		if (obj instanceof RevisionControlled)
		{
			RevisionControlled iterationObject = (RevisionControlled) obj;
			System.out.printf("numer> %s - name> %s - version> %s %n", iterationObject.getDisplayIdentifier(), iterationObject.getName(), iterationObject.getIterationDisplayIdentifier());
		}
	}
} catch (QueryException e)
{
	e.printStackTrace();
} catch (WTException e)
{
	e.printStackTrace();
}

 

PetrH

View solution in original post

14 REPLIES 14

Hi @AB_9905442 

You can try this method that returns all versions so the history is based on all version. 

Information can be collected from each object that is returned in a query... 

 

QueryResult allVersions = VersionControlHelper.service.allVersionsOf(document);
while (allVersions.hasMoreElements())
{
	Object obj = allVersions.nextElement();
	if (obj instanceof RevisionControlled)
	{
		RevisionControlled iterationObject = (RevisionControlled) obj;
	}
}

 

then you can use following methods to get some info.. 

 

iterationObject.getCreateTimestamp();
iterationObject.getCreator();
iterationObject.getModifier();
iterationObject.getVersionDisplayIdentifier();

 

 the document variable can be Mater object or any Versioned one. 

example

WTDocument or WTDocumentMaster

EPMDocument or EPMDocumentMaster

 

PetrH

 

Hello ,
Thank you for the methode , but it display only 2 iteration 

ptc.png

AB_9905442
4-Participant
(To:AB_9905442)

PTC01.png

 this is our example 

Have you used they Query Builder before? You could create a query to display this information

 

Some info to help you get started: https://www.ptc.com/en/support/wnc-reporting-landing/wnc-reporting-landing-main/querybuilder-intro/qb-intro?overlay=BDDBFF62-6C2F-436C-A38B-BF1BDD6B3F23&source=search

 

rleir
17-Peridot
(To:AB_9905442)

Programmatically as in an external program making REST OData API calls? Or an external program making REST calls for QB data? Or a program integrated in the WC server?

AB_9905442
4-Participant
(To:rleir)

Hello @rleir ,
A methode like  the first comment 

Hi @AB_9905442 

And is it wrong? why? you didn't provide real data if there are just versions A.1 and B.1 the result is correct.

PetrH

PTC01.png

this is our example 

Hi @AB_9905442 

Obviously the method returns just latest versions of all revisions. 

 

So you can use another method as a query definition

 

WTArrayList retValue = new WTArrayList();
QuerySpec queryspec;
try
{
if (revObj instanceof WTDocument)
{
	queryspec = new QuerySpec();
	int idWTDocObject = queryspec.appendClassList(WTDocument.class, true);
	//podmínka vyhledávání
	CompositeWhereExpression andCondition = new CompositeWhereExpression(LogicalOperator.AND);

	andCondition.append(new SearchCondition(WTDocument.class, WTDocument.NUMBER, SearchCondition.LIKE, ((WTDocument) revObj).getNumber()), new int[]{idWTDocObject});
	queryspec.appendWhere(andCondition, new int[]{idWTDocObject, idWTDocObject});
	queryspec.appendOrderBy(new OrderBy(new ClassAttribute(WTDocument.class, WTDocument.MODIFY_TIMESTAMP), false), new int[]{0});

	QueryResult qResult= PersistenceHelper.manager.find((StatementSpec) queryspec);

	retValue.addAll(qResult);

}
} catch (WTException e)
{
	e.printStackTrace();
}

 

PetrH

@HelesicPetr  Thank you for the methode , its display all the documents 
from this  can  i get  version , file name , state , comments ,modified by and last modified  as the picture ?

@AB_9905442 

Yes, go one by one result document version and get all the information what you need.

PetrH

Hi @AB_9905442 

btw the VersionControlHelper contains an other method that returns all iterations. allIterationsFrom

 

try
{
	WTDocument document = getDocumentByNumber("0000000142");
	QueryResult allVersions = VersionControlHelper.service.allIterationsFrom(document);
	while (allVersions.hasMoreElements())
	{
		Object obj = allVersions.nextElement();
		if (obj instanceof RevisionControlled)
		{
			RevisionControlled iterationObject = (RevisionControlled) obj;
			System.out.printf("numer> %s - name> %s - version> %s %n", iterationObject.getDisplayIdentifier(), iterationObject.getName(), iterationObject.getIterationDisplayIdentifier());
		}
	}
} catch (QueryException e)
{
	e.printStackTrace();
} catch (WTException e)
{
	e.printStackTrace();
}

 

PetrH

AB_9905442
4-Participant
(To:AB_9905442)

I implemented this methode  it's ok but the first iteration not exist ( A1) 

 

 WTDocument refreshedDoc = (WTDocument) PersistenceHelper.manager.refresh(document);

	        // Get the version history
	        QueryResult versionHistory = VersionControlHelper.service.allIterationsOf(refreshedDoc.getMaster());

	        // Display the version history information
	        int i=1;
	        
	        
	        while (versionHistory.hasMoreElements()) {
	        	
	        	String iteration="";
	        	String version="";
	        	String fileName="";
	        	String state="";
	        	String coments="";
	        	String modifyBy="";
	        	String lastModified="";
	            Object versioned = versionHistory.nextElement();
	            
	            
	            if (versioned instanceof Iterated) {
	                Iterated iterated = (Iterated) versioned;
	                iteration = getVersion(iterated);
	                
	                IterationInfo iterationInfo = iterated.getIterationInfo();
	                coments=iterationInfo.getNote();
	                
	                modifyBy= iterationInfo.getModifier().getFullName();
	            
	               // taskLogger.debug("iteration: " + iteration);
	               // taskLogger.debug("getModifierName: " + iterated.getModifierName());	  
	                modifyBy=iterated.getModifierName();
	                lastModified=iterated.getCreatorName();
	                if (iterated instanceof LifeCycleManaged) {
	                    LifeCycleManaged lifeCycleManaged = (LifeCycleManaged) iterated;
	                    state= lifeCycleManaged.getLifeCycleState().toString();
	                   
	                    //taskLogger.debug("state: " + state);
	                    
	                }	               
	                if (iterated instanceof WTDocument) {
	                    WTDocument doc = (WTDocument) iterated;	                    
	                    //taskLogger.debug("doc: " + doc.getNumber());
	                    ContentHolder holder= ContentHelper.service.getContents(doc);
	                    ContentItem  ci = ContentHelper.getPrimary((FormatContentHolder) holder);
	                    ApplicationData  ad = (ApplicationData) ci;
	                    fileName = ad.getFileName();
	                    
	                    //taskLogger.debug(doc.getIterationInfo().getIdentifier().getValue());
	                   // taskLogger.debug(doc.getVersionInfo().getIdentifier().getValue());
	                    version=doc.getVersionInfo().getIdentifier().getValue();
	                }	                                	                
	            }
	            taskLogger.debug("----------------------"+i+"---------------------------------");
	            
	            taskLogger.debug(version+iteration+"---"+fileName+"---"+state+"---"+coments+"---"+modifyBy+"---"+lastModified);
	            i++;
	        }	

 



how can i display also A1 iteration 

PTC01.png

@AB_9905442 

I've already answered.

PetrH

Announcements

Top Tags