Skip to main content
8-Gravel
January 16, 2023
Solved

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

  • January 16, 2023
  • 1 reply
  • 2002 views

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);

       }

  }

Best answer by HelesicPetr

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

 

1 reply

Dina_S8-GravelAuthor
8-Gravel
January 17, 2023

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){

HelesicPetr
22-Sapphire II
22-Sapphire II
January 17, 2023

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_S8-GravelAuthor
8-Gravel
January 18, 2023

Thank you for the clue.