Skip to main content
Jan 16, 2023 4:07 PM UTC
Solved

How to check if downstream view of the WT part exists?

Hi All,

I want to create a "Manufacturing" view for the part included in the Change task, but I want to do it only if it doesn't exist.

Now I use this code without checking. And I want to add something like " if Manufacturing view for obj ==null then" 

 

wt.fc.QueryResult qr = wt.change2.ChangeHelper2.service.getChangeablesBefore((wt.change2.ChangeOrderIfc) primaryBusinessObject);

while(qr.hasMoreElements())

{

  wt.fc.WTObject  obj =(wt.fc.WTObject) qr.nextElement();

   if(obj instanceof wt.part.WTPart)

      {

       wt.part.WTPart prt = (wt.part.WTPart) obj;

       wt.part.WTPart ManufPart = (wt.part.WTPart)

       ManufPart = (wt.vc.views.ViewManageable)obj, "Manufacturing")

       wt.vc.views.ViewHelper.service.newBranchForView((wt.vc.views.ViewManageable)obj, "Manufacturing");

 

      ManufPart = (wt.part.WTPart)wt.fc.PersistenceHelper.manager.store(ManufPart);

       }

  }

Jan 17, 2023 1:51 PM UTC

Hi @Dina_S 

It is easy.

Filter the results based on your view

 

QueryResult qrUstr = PersistenceHelper.manager.navigate(part,EquivalenceLink.DOWNSTREAM_ROLE,wt.associativity.EquivalenceLink.class, true);

		WTPart dwWTP = null;
		while (qrUstr.hasMoreElements())
		{
			dwWTP = (WTPart) qrUstr.nextElement();
			if (dwWTP.getViewName().equalsIgnoreCase("manufacturing"))
			{
				System.out.print(dwWTP.getNumber()); // use it as you need. 
			}
		}

 

PetrH

 

5 replies

Dina_SAuthor
Jan 17, 2023 1:35 PM UTC

I have found this

https://www.ptc.com/en/support/article/cs47538?language=en&posno=4&q=ViewHelper.service.newBranchForView&source=search

 

wt.fc.PersistenceHelper.manager.navigate(reference.getObject(),wt.associativity.EquivalenceLink.DOWNSTREAM_ROLE, wt.associativity.EquivalenceLink.class);

 

I need help finding out how to use this. I need only the "Manufacturing view" part, not the "Service view" one. And I don't know how to check the assigned view for the object. I would really appreciate it if someone could help me.

 

So I tried this and it doesn't work like I want:

 

wt.fc.QueryResult AllDownPart = wt.fc.PersistenceHelper.manager.navigate(obj,

wt.associativity.EquivalenceLink.DOWNSTREAM_ROLE, wt.associativity.EquivalenceLink.class,true);

 

if(AllDownPart != null){

Jan 17, 2023 1:51 PM UTC

Hi @Dina_S 

It is easy.

Filter the results based on your view

 

QueryResult qrUstr = PersistenceHelper.manager.navigate(part,EquivalenceLink.DOWNSTREAM_ROLE,wt.associativity.EquivalenceLink.class, true);

		WTPart dwWTP = null;
		while (qrUstr.hasMoreElements())
		{
			dwWTP = (WTPart) qrUstr.nextElement();
			if (dwWTP.getViewName().equalsIgnoreCase("manufacturing"))
			{
				System.out.print(dwWTP.getNumber()); // use it as you need. 
			}
		}

 

PetrH

 

Dina_SAuthor
Jan 18, 2023 10:18 AM UTC

Thank you for the clue.