Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
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);
}
}
Solved! Go to Solution.
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
I have found this
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){
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
Thank you for the clue.
It is also important not to forget to create an Equivalence link.
The object is taken from Change Notice.
Below full working code without checking procedures:
wt.fc.QueryResult qr = wt.change2.ChangeHelper2.service.getChangeablesBefore((wt.change2.ChangeOrderIfc) primaryBusinessObject);
//qr changeable before= vector all Deign part for Manufacturing
while(qr.hasMoreElements())
{
wt.fc.WTObject obj =(wt.fc.WTObject) qr.nextElement();
//obj =one design part from implementation tasks
if(obj instanceof wt.part.WTPart)
{
wt.part.WTPart prt = (wt.part.WTPart) obj;
wt.fc.QueryResult AllDown = wt.fc.PersistenceHelper.manager.navigate(prt, wt.associativity.EquivalenceLink.DOWNSTREAM_ROLE, wt.associativity.EquivalenceLink.class,true);
//all downstream parts
wt.part.WTPart ManuPart= null;
// empty part for Manufacturing
wt.part.WTPart dwWTP = null;
// empty part for checking if Manufacturing
while (AllDown.hasMoreElements())
{
dwWTP = (wt.part.WTPart) AllDown.nextElement();
if (dwWTP.getViewName().equalsIgnoreCase("Manufacturing"))
{
System.out.print(dwWTP.getNumber());
ManuPart = dwWTP;
}
}
if(ManuPart==null)
{
ManuPart = (wt.part.WTPart)wt.vc.views.ViewHelper.service.newBranchForView((wt.vc.views.ViewManageable)prt, "Manufacturing");
ManuPart = (wt.part.WTPart)wt.fc.PersistenceHelper.manager.store(ManuPart);
//create equivelencelink between these 2 parts
wt.associativity.EquivalenceLink link1 = wt.associativity.EquivalenceLink.newEquivalenceLink(prt,ManuPart);
link1.setIsConsumable(true);
link1.setUpstreamContextRef(prt.getView());
link1.setDownstreamContextRef(ManuPart.getView());
link1 = (wt.associativity.EquivalenceLink) wt.fc.PersistenceHelper.manager.save(link1);
}
}
}
I also found that it is important not to forget to create EquivalenceLink :).