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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

How can I get Part Where Used (Latest view) from REST API ?

tomnelson
4-Participant

How can I get Part Where Used (Latest view) from REST API ?

I am using Windchill 12.1.2 with the following API to fetch a two level where used for a part, however it is returning Version B (RELEASED) and C (INWORK) for the same part in the results. The results mimic what I see in the Windchill UI on the Where Used tab using the All Revisions view. I want my REST API to return the results as if the Latest view on the Where Used tab is selected. How do I do that in my REST API?

https://<wc_host>/Windchill/servlet/odata/ProdMgmt/Parts('OR:wt.part.WTPart:143038')?$select=Identity,State&$expand=UsedBy($count=true;$levels=2;$select=Identity,State)

 

12 REPLIES 12

I believe you're just missing the "$filter=state eq 'RELEASED'" which you should be able to enter between your $select and $expand.  I used the REST tool in the Documentation page of Windchill to build this example.  Instead of filtering by state I just filtered the UsedBy results by PN, for this example.

 

WINDCHILL/servlet/odata/v5/ProdMgmt/Parts('OR%3Awt.part.WTPart%3A4277973910')/UsedBy?%24select=Identity%2CState&%24filter=Number%20eq%20'MyFilteredUsedByPartNumber'&%24count=true&%24expand=UsedBy(%24count%3Dtrue%3B%24levels%3D2%3B%24select%3DIdentity%2CState)

 So instead of Number eq 'yournumber' you'd just use State eq 'yourState'

Thank you for the suggestion, but I do not want to filter for only RELEASED state. I need the latest version. I want my REST API to return the same results as what is in the screenshot below of a Latest view Where Used.

wu_latest_view..png

The REST API , I posted above is returning the results that match an All Revisions view Where Used, see screenshot below. I DO NOT want that, I desire the Latest view results above.

wu_all_revisions_view..png

Apologies I misread that...  

 

Perhaps this is what you're looking for?  I'm not very experienced with WRS so again, apologies if you looked here already.

https://www.ptc.com/support/-/media/support/refdocs/Windchill_REST_Services/2,-d-,6/wrs.pdf?sc_lang=en (Excerpt from Page 115)

Retrieving the Latest Version of an Entity
You can retrieve the latest version of an entity using the custom query option
ptc.search.latestversion. The option takes true or false as input
value.
When you specify the query option as true, it limits the search results to retrieve
only the latest version of the entity.
If the query option is specified as false, the search results retrieve the latest
iteration of each revision for the entity.
For example, the following URL retrieves the latest version of the parts:
GET /Windchill/servlet/odata/ProdMgmt/Parts?$filter=
startswith(Name,'Axle')&ptc.search.latestversion=true
The following rules apply to ptc.search.latestversion option:
• The value specified for latest version in the query option gets precedence over
the value set for Latest Version Search preference in Windchill.
• If the query option is not specified in the request URL, the value specified for
Latest Version Search preference in Windchill is used.
• If the query option is not specified in the request URL and the Latest Version
Search preference is not explicitly set

Yep, thanks for trying, the query parameter ptc.search.latestversion=true doesn't make any difference either.

How to use ptc.search.latestversion=true  in UsedBy?

ptc.search.latestversion=true  this works on Part or Document object directly , how to use this filter on any link object?

tomnelson
4-Participant
(To:TD_1000000)

I haven't found ptc.search.latestversion=true to work on the UsedBy link. As you stated, I believe that only works on a Part or Document object.

So, what is the solution of this?

tomnelson
4-Participant
(To:TD_1000000)

I don't have one, that is why I posted the original question. I am hoping someone knowledgeable has an answer.

I've only just seen your post but you could try the following:

WINDCHILL/servlet/odata/v5/ProdMgmt/Parts('OR%3Awt.part.WTPart%3A4277973910')?$expand=UsedBy($filter=Latest eq true)

 this should filter the WhereUsed elements to only those that have the "Latest" attribute set to true.

Thank you for the reply, but that doesn't provide the output equal to the Where Used "Latest" filter screenshot I provided above. This filter actually produces more results because it includes all versions of Parts where Latest=true which returned the Latest version of each part in the structure for each State (In Work or Released) of the part.

You are right, my example data set was too simple! I investigated some more. I believe that you could only achieve what you want to do with the WRS if the WhereUsed implementation would directly implement the possibility of a "latest filter".

 

I remembered that in the older Swagger rest services you can do what you require. The following query allows that a navigationCriteria is passed.

WINDCHILL/Windchill/servlet/rest/structure/objects/VR%3Awt.part.WTPart%3A210986/ancestors?$select=name%2Cversion&inline=false&levels=1

If you leave out the navigationCriteria it should default to "latest" and provide you with the result that you need.
I'm not sure if the swagger approach is a valid workaround for you, but I believe your request qualifies as a good enhancement request for the WRS.

DmitryC
12-Amethyst
(To:tomnelson)

I'm doing it in several steps:

 

1. Do the usual UsedBy, but add all the revisions as an expansion:

 

http://windchillhost/Windchill/servlet/odata/ProdMgmt/Parts('OR:wt.part.WTPart:123456789')/UsedBy?$select=Number,State,Revision,Name&$orderby=Number%20asc,Revision%20desc&$expand=Revisions($select=Number,State,Revision)

 

 

2. Create an array with revisions as in Windchill revisions order:

 

const revList = ["-", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "?", 
	"A", "B", "C", "D",...];

 

 

3. Reduce the reply to unique records (by part number) with the latest revision:

 

				let result = dataObj.value.reduce((acc, curr) => {
					let number = curr.Number;
					if (!acc[number]) {
						acc[number] = curr;
					} else if (revList.indexOf(acc[number].Revision) < revList.indexOf(curr.Revision)) {
						acc[number] = curr;
					}
					return acc;
				}, {});

				let uniqueObjects = Object.values(result);

 

 

4. Then I can check if I'm left with actually the latest revision:

if (uniqueObjects[i].Revision === uniqueObjects[i].Revisions[0].Revision)

 

Top Tags