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

Community Tip - You can change your system assigned username to something more personal in your community settings. X

What is the REST API to get Reference documents on a given WTDocument in Windchill?

KD_10675014
3-Newcomer

What is the REST API to get Reference documents on a given WTDocument in Windchill?

I am using Windchill PDMLink Release 12.1 and Datecode with CPS 12.1.0.0

What is the REST API to get Reference documents on a given WTDocument in Windchill?

I found a very similar QA on Java API but I want to know how to do it using REST:
https://www.ptc.com/en/support/article/CS183968

7 REPLIES 7

Hi @KD_10675014 

In Windchill documentation on your system you have full restAPI documentation.

<server>/Windchill/netmarkets/html/wrs/doc.html

check all document rest functions and you can find lot of useful functions

HelesicPetr_0-1687418591658.png

 

Unfortunately I can not locate any function to retrieve a dependency link.

That means it may not exist. 

 

PetrH

Hello KD_10675014,

I'm Charles from PTC Technical Support in Europe, I will provide you assistance on this question. Was the information provided helpful somehow?

KR,

Charles.

Thank you, Charles. 

So far my problem is not solved. /Documents/PTC.DocMagmt.ReferenceDocument returns all reference documents. But that this not what I am looking for. PetrH also said that. 

I am looking for a REST API endpoint that will return all reference documents for a given WTDocument. 

 

I found a very similar QA on Java API but I want to know how to do it using REST or how to create a custom REST endpoint:
https://www.ptc.com/en/support/article/CS183968

Hi @KD_10675014 

Start to study this article CS183488 with many resources how to customize rest services.

 

Windchill REST Services User’s Guide point to the customization domains and this can help you.

 

Page 63 Examples for Customizing Domains

 

PetrH

Creating a custom endpoint will be my last resort. Can I do what I want to do using an existing endpoint? If not, can you provide me with an example of a custom end point that does what I want to do? 

Hello KD_10675014,

May I suggest you open a new case (customization) for this question?

KR,

Charles.

Hi KD_10675014,

There does not appear to be any REST API for document to document usage, document to document reference or document to document described by relationships. There are however, thos elinks for WTParts, so it is surprising that the equivalent for documents do not exist (well not really surprising in my opinion because WTDocument relationships seem to be an after thought).

How I solved this was to write my own custom java backend code for each of the above 3 relationship types. I'm quite happy to share my code. I have several "versions" for creating a link, updating a link, deleting a link of each of the 3 types with or without attributes, with or without revisions. There has been a lot of frustrations because even though on the surface you would think you could use all the code for WTParts and just replace with WTDocument (master, usage...), it simply does not work the same. For example, if you wish to update a custom attribute on a document usage link, you cannot. YOu have to delete the existing link and create a new one with the new value for the attribute. With WTPartUsage you can however, just update the attribute.

 

Here is one sample function for creating a document ot document usage link. You can ignote the iWebAppId part. It is used to get the appropriate user for the organization because we have  multiple organizations. You could hardcode the principal user if desired.

	 public Boolean setDocDocLink(String sUser, String sParentDocNo, String sChildDocNumber, String sCheckInComments, String sDocUsageType, int iWebAppId) throws WTException, RemoteException, InvocationTargetException
	 {
        if (!RemoteMethodServer.ServerFlag)
        {
            RemoteMethodServer ms = RemoteMethodServer.getDefault();
            Class[] argTypes = {String.class, String.class, String.class, String.class, String.class, int.class};
            Object[] argValues = {sUser, sParentDocNo, sChildDocNumber, sCheckInComments, sDocUsageType, iWebAppId};
            ms.invoke("setDocDocLink", null, this, argTypes, argValues);
            return true;
        }

        SessionContext.newContext();
        String sUsername = getBackendUser(iWebAppId);
        SessionHelper.manager.setPrincipal(sUsername);

        Transaction trans = new Transaction();
	        
        try
        {
	        trans.start();
	        WTDocument DocChild = getDocumentByNumber(sChildDocNumber);
			if(DocChild != null)
			{
				WTDocumentMaster masterChild = (WTDocumentMaster)DocChild.getMaster();
				WTDocument DocParent = getDocumentByNumber(sParentDocNo);
				WTDocumentUsageLink link = new WTDocumentUsageLink();
/*				Quantity DocQty = new Quantity();
				DocQty.setAmount(dQty);
				if(sUnit.equals(""))
					DocQty.setUnit(QuantityUnit.EA);
				else
					DocQty.setUnit(QuantityUnit.toQuantityUnit(sUnit));
				link.setQuantity(DocQty);
*/				Folder checkoutFolder = wt.vc.wip.WorkInProgressHelper.service.getCheckoutFolder();
				CheckoutLink col = null;
				col = WorkInProgressHelper.service.checkout((WTDocument)DocParent,checkoutFolder,"");
				WTDocument DocParent2 = (WTDocument)col.getWorkingCopy();
				PersistableAdapter obj = new PersistableAdapter(DocParent2,null,Locale.US,new UpdateOperationIdentifier());
			    obj.load("RegainPortalUser");
				obj.set("RegainPortalUser", sUser);
				obj.apply();
				PersistenceHelper.manager.modify(DocParent2);				

				link.setTypeDefinitionReference(getTypeDef(sDocUsageType));
				link.setRoleAObject(DocParent2);
				link.setRoleBObject(masterChild);
				link = (WTDocumentUsageLink)PersistenceHelper.manager.store(link);
				PersistenceHelper.manager.refresh(link);
				DocParent2 = (WTDocument)WorkInProgressHelper.service.checkin(DocParent2,sCheckInComments);
			}
		 
			trans.commit();
			trans = null;
			return true;
	    }
	    catch(Throwable t) 
	    {
	        throw new ExceptionInInitializerError(t);
	    } 
	    finally 
	    {
	        if(trans != null) 
	        {
	        	trans.rollback();
	        }
	    }	        
	 }

Also, I always set a custom attribute for our front end user which is the bit about RegainPortalUser. If you don't want to set an attribute on the parent document, just remove that bit.

Finally I have a useful funciton that returns the parent document object from the document number, because this is what needs to be checked out and checked back in after creating the link.

	public static WTDocument getDocumentByNumber(String sDocNumber) throws WTException 
	{
		// TODO Auto-generated method stub
	    QuerySpec qs = new QuerySpec(WTDocument.class);
	    SearchCondition condition = new SearchCondition(WTDocument.class, WTDocument.NUMBER, SearchCondition.EQUAL, sDocNumber);
	    qs.appendWhere(condition, new int[]{0});
	    QueryResult qr = PersistenceHelper.manager.find((StatementSpec)qs);
	    WTDocument doc = null;
	    WTDocument doc2 = null;
		while(qr.hasMoreElements())
		{
			doc = (WTDocument)qr.nextElement();
			break;
		}
		if(doc != null)
		{
			QueryResult qr2 = VersionControlHelper.service.allVersionsOf(doc);
			doc2= (WTDocument)qr2.nextElement();
		}
		
		return doc2;
	}

This setDocDocLink function I expose as a REST API so I can call it from my custom frontend.

 

Unfortunately, every part of the process has to be customised it seems.

 

Announcements


Top Tags