Skip to main content
1-Visitor
November 10, 2016
Question

Query for latest revision of WTDocument (current PrimaryBusinessObject)

  • November 10, 2016
  • 2 replies
  • 6441 views

Hello,

I'm designing a workflow that will send out notifications at specific times post-due (i.e. 10 days late, 15 days late, etc.) and I'd like to end this workflow if the revision process for the specific WTDocument has started (i.e. AA.4 -> AB.1, so the AB revision exists in Windchill).  However, within a workflow for a specific revision of a WTDocument, I'm not sure how to query for the "latest revision" of the PrimaryBusinessObject since I believe this will only return the revision of the document that initiated the workflow.  Any thoughts?  Perhaps I've misunderstood something very simple.

Thanks!

2 replies

20-Turquoise
November 10, 2016

...

However, within a workflow for a specific revision of a WTDocument, I'm not sure how to query for the "latest revision" of the PrimaryBusinessObject

Take a look at this post:

Re: Download Latest version/iteration of EPM document

Try something like this (not tested....):

WTDocument currentDoc = (WTDocument) PrimaryBusinessObject;

WTDocumentMaster docMaster = currentDoc.getMaster();

WTDocument latestDoc = (WTDocument)wt.vc.VersionControlHelper.service.allVersionsOf(docMaster).nextElement();

kweiss1-VisitorAuthor
1-Visitor
November 10, 2016

What determines the 'Master' relationship?  Does that need to be declared at some point or is it implicitly done in Windchill by 'revisioning'? 


Thanks!

20-Turquoise
November 11, 2016

Kevin Weiss wrote:

What determines the 'Master' relationship?  Does that need to be declared at some point or is it implicitly done in Windchill by 'revisioning'? 


All iterated objects in Windchill have a master which is created the first time you create an object (wtdocument, epmdocument, wtpart, etc). There is one master in which "master" attributes such as number, name, fileName (if appropriate), and etc are defined. This is a core part of Windchill java objects and the underlying database tables. There is a database table for the master (wtdocumentmaster for documents) and a database table for the versions (wtdocument for documents). Some other database tables:

  • epmdocumentmaster
  • epmdocument
  • wtpartmaster
  • wtpart

If you are wanting to learn more about this I would suggest taking a look at the training offered by felcosolutions.com:

FELCO Solutions

I have taken both the "Windchill Automation" and the "Windchill Customization". Very good courses. The "Windchill Automation" extensively covers what you are attempting to do here.

1-Visitor
November 18, 2016

Hi,

You can use the following code to get the latest revision of PBO (WTDocument).

WTDocument latestDoc ;

String latestRev = "";

WTDocument currentDoc = (WTDocument) primaryBusinessObject;

QueryResult allDocVersions=VersionControlHelper.service.allVersionsOf((Versioned)primaryBusinessObject);

if(allDocVersions !=null && allDocVersions.size() > 0)

{

latestDoc=(WTDocument)allVersions.nextElement();

latestRev = latestDoc.getVersionIdentfier.getValue();

System.out.println("Latest Doc===="+latestDoc.getName()+"Latest Revision ===="+latestRev);

}



kweiss1-VisitorAuthor
1-Visitor
November 30, 2016
  1. Will I need to loop through AllDocVersions until I get to the latest version or will the QueryResult link the position of the PBO within it so that I only need to do nextElement() once?
  2. What is returned when I use .nextElement() and the PBO *is* the last element in the QueryResult?
1-Visitor
December 1, 2016

Hi,

Below are the answers to your query:

  1. Will I need to loop through AllDocVersions until I get to the latest version or will the QueryResult link the position of the PBO within it so that I only need to do nextElement() once? Yes
  2. What is returned when I use .nextElement() and the PBO *is* the last element in the QueryResult? Null