Skip to main content
13-Aquamarine
November 21, 2024
Solved

Is there any Direct API to get latest version/ Iteration of object based on View .

  • November 21, 2024
  • 2 replies
  • 1491 views

Reference topic - https://community.ptc.com/t5/Windchill/Report-to-list-WTParts-of-particular-view/m-p/96770#M11366

Hi @Marco_Tosin

 

I have WTPart on 3.4 with design View 

And I have created a new view for the same object and that is on 0.1 Custom View .

 

So is there any Direct API to get latest version/ Iteration of object based on View .

 

 

Best answer by HelesicPetr

Hi @@_1647 

generally no. There is no direct api to get latest design view.

I usually use a querySpec to get latest versions and then return the last Design one. 

String partNumber = "searchdNumber";
WTPart searchedDesignPart = null;
try
{
	QuerySpec queryspec;
	queryspec = new QuerySpec();
	int idWTPartObject = queryspec.appendClassList(WTPart.class, true);
	CompositeWhereExpression andCondition = new CompositeWhereExpression(LogicalOperator.AND);
	andCondition.append(new SearchCondition(WTPart.class, WTPart.LATEST_ITERATION, SearchCondition.IS_TRUE), new int[]{idWTPartObject});
	andCondition.append(new SearchCondition(WTPart.class, WTPart.NUMBER, SearchCondition.LIKE, partNumber), new int[]{idWTPartObject});
	queryspec.appendWhere(andCondition, new int[]{idWTPartObject, idWTPartObject});
	queryspec.appendOrderBy(new OrderBy(new ClassAttribute(WTPart.class, WTPart.MODIFY_TIMESTAMP), false), new int[]{0});

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

	while (resPart.hasMoreElements())
	{
		Object obj[] = (Object[]) resPart.nextElement();
		WTPart part = (WTPart) obj[0];
		if (part.getViewName().equalsIgnoreCase("Design"))
		{
			searchedDesignPart = part;
		}
	}
} catch (WTException e)
{
	e.printStackTrace();
}

PetrH

2 replies

HelesicPetr
22-Sapphire II
22-Sapphire II
November 21, 2024

Hi @@_1647 

generally no. There is no direct api to get latest design view.

I usually use a querySpec to get latest versions and then return the last Design one. 

String partNumber = "searchdNumber";
WTPart searchedDesignPart = null;
try
{
	QuerySpec queryspec;
	queryspec = new QuerySpec();
	int idWTPartObject = queryspec.appendClassList(WTPart.class, true);
	CompositeWhereExpression andCondition = new CompositeWhereExpression(LogicalOperator.AND);
	andCondition.append(new SearchCondition(WTPart.class, WTPart.LATEST_ITERATION, SearchCondition.IS_TRUE), new int[]{idWTPartObject});
	andCondition.append(new SearchCondition(WTPart.class, WTPart.NUMBER, SearchCondition.LIKE, partNumber), new int[]{idWTPartObject});
	queryspec.appendWhere(andCondition, new int[]{idWTPartObject, idWTPartObject});
	queryspec.appendOrderBy(new OrderBy(new ClassAttribute(WTPart.class, WTPart.MODIFY_TIMESTAMP), false), new int[]{0});

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

	while (resPart.hasMoreElements())
	{
		Object obj[] = (Object[]) resPart.nextElement();
		WTPart part = (WTPart) obj[0];
		if (part.getViewName().equalsIgnoreCase("Design"))
		{
			searchedDesignPart = part;
		}
	}
} catch (WTException e)
{
	e.printStackTrace();
}

PetrH

@_164713-AquamarineAuthor
13-Aquamarine
November 21, 2024

Hi HelesicPetr,

Thank you for help.

Actually I want to get latest iteration of  each view of same object.

 

HelesicPetr
22-Sapphire II
22-Sapphire II
November 22, 2024

Hi @@_1647 

So where is the problem to get all latest version/iterations of each view by the query I've provided?

PetrH

18-Opal
November 21, 2024

As usual, @HelesicPetr is correct.  There is no getLatestWTPartAtView method. You have to write your own.

 

I came up with what I think is a fairly simple method that accepts two arguments, WTPart number and View name.

The method gets the desired view using a simple QuerySpec.

If the QuerySpec returns a View (perhaps the view name entered does not exist) the View is used in a second QuerySpec that uses the View and the WTPart number.

 

The trick is at use order by to set the order of the QueryResult such that the first object in the QueryResult is the object you want.  You simply return that first object.  No need to use a while loop.

 

In the images below I show the order the iterations occur in the QueryResult.

Latest rev.iteration to first rev.iteration

d_graham_0-1732216624432.png

 

Now, suppose I want the latest version first but with first iteration, B.1, B.2, B.3, A.1, you get the idea.

I simply flip the sort order, and I get the new ordering.

d_graham_1-1732216839709.png

 

If I want A.1 first (first iteration to latest iteration) I flip the sort order again and I get the results I want.

d_graham_2-1732217059473.png

 

David

 

 

@_164713-AquamarineAuthor
13-Aquamarine
November 22, 2024

Thank D_graham,

For your detailed explanation about results.

It was very helpful to understand outputs.