Hi All,
Anybody used FolderHelper.assignFolderByReference(part, oRef); to move objects from one container to another? Please help with the usage. I couldn't find a way to use this piece of code properly.
Thanks,
Wasim
Solved! Go to Solution.
Wasim
Paste this two lines of code in workflow
wt.part.WTPart pbo =(wt.part.WTPart)primaryBusinessObject;
ext.CustomWTPartMover.PartMover(pbo ,"GOLF_CART ","Manufacturing");
//Here GOLF_CART Target product Name & Manufacturing is my folder Name inside Target product
This my Java class called in workflow
package ext;
import wt.dataops.containermove.ContainerMoveHelper;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.fc.collections.WTValuedHashMap;
import wt.folder.Folder;
import wt.folder.FolderHelper;
import wt.inf.container.WTContainer;
import wt.inf.container.WTContainerRef;
import wt.method.RemoteAccess;
import wt.part.WTPart;
import wt.pdmlink.PDMLinkProduct;
import wt.pds.StatementSpec;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.util.WTException;
public class CustomWTPartMover implements RemoteAccess{
public static void PartMover(WTPart part,String ContainerName,String location)
{
try {
WTContainer cont=getMyProduct(ContainerName);
WTContainerRef containerRef = WTContainerRef.newWTContainerRef(cont);
Folder folder = FolderHelper.service.getFolder("/Default/"+location, containerRef);
WTValuedHashMap map = new WTValuedHashMap();
map.put(part,folder);
ContainerMoveHelper.service.moveAllVersions(map);
}
catch (WTException e) {
e.printStackTrace();
}
}
public static PDMLinkProduct getMyProduct(String ContainerName)
{
PDMLinkProduct product = null;
try {
QuerySpec qs = new QuerySpec(PDMLinkProduct.class);
qs.appendWhere(
new SearchCondition(PDMLinkProduct.class,
PDMLinkProduct.NAME, SearchCondition.EQUAL,
ContainerName), new int[] { 0 });
QueryResult qr;
qr = PersistenceHelper.manager.find((StatementSpec) qs);
while (qr.hasMoreElements()) {
product = (PDMLinkProduct) qr.nextElement();
}
} catch (WTException e) {
e.printStackTrace();
}
return product;
}
}
Hello!
I have not tried this but maybe you can try the below code instead?
WTPart part = getPart("name"); | |
SubFolder folder = getSubFolder("libraryName", "folderPath"); | |
try{ | |
FolderHelper.assignLocation(part, folder); | |
}catch(Exception e){ | |
e.printStackTrace(); | |
} |
I know the API is deprecated in Windchill 10 but there are some other similar methods there you can use that will probably do the same.
Best regards,
Peter
Thanks a lot Peter. I'll give it a try and will let you know how it works.
Wasim,
If you want to move objects then you better use below API
wt.dataops.containermove.ContainerMoveHelper.service.moveAllVersions(map);
// //////// MOVE OBJECTS /////////
This way, You will be able to move objects from library to product or vice versa.
Thanks,
Amit.
Hi Amit,
Thanks for your prompt response. Do you have an example code or something which could tell me how to use it?? I'd really appreciate that.
Thanks,
Wasim
Wasim
Here to go
public static void myCustomMover(String docNumber)
{
try {
WTDocument doc=getWTDoc(docNumber);
WTContainer cont=doc.getContainer();//you give different container also
WTContainerRef containerRef = WTContainerRef.newWTContainerRef(cont);
String location="MyFolder//Documents/";
Folder folder = FolderHelper.service.getFolder("/Default/"+location, containerRef);
WTValuedHashMap map = new WTValuedHashMap();
map.put(doc,folder);
ContainerMoveHelper.service.moveAllVersions(map);
}
catch (WTException e) {
e.printStackTrace();
}
}
Thanks & Regards
Manikandan
Thanks Mani
Hi Mani,
I appreciate your efforts on this. I am struggling to create a workflow which checks if the document created is a part? If yes, then move to Product 'XYZ' and a folder called WTPart into it.
When I tried to put the code you suggested, and it wont work. Gives error. The following which I tried:
java.lang.String pboType=primaryBusinessObject.getClass().getName();
if (pboType.equals("wt.part.WTPart"))
{
WTPart doc=pboType.getNumber();
WTContainer cont=doc.getContainer("XYZ");//you give different container also
}
Error
--------------------------------------------
Checking Syntax...
D:\ptc\Windchill10\Windchill\temp\WfExpression3373668605.java:26: cannot find symbol
symbol : method getNumber()
location: class java.lang.String
wt.part.WTPart doc=pboType.getNumber();
^
D:\ptc\Windchill10\Windchill\temp\WfExpression3373668605.java:27: cannot find symbol
symbol : class WTContainer
location: class wt.workflow.expr.WfExpression3373668605
WTContainer cont=doc.getContainer("XYZ");//you give different container also
^
D:\ptc\Windchill10\Windchill\temp\WfExpression3373668605.java:27: getContainer() in wt.part._WTPart cannot be applied to (java.lang.String)
WTContainer cont=doc.getContainer("XYZ");//you give different container also
^
3 errors
Syntax check complete.
-----------------------------------------------------------
Any help??
Thanks,
Wasim
Wasim
Paste this two lines of code in workflow
wt.part.WTPart pbo =(wt.part.WTPart)primaryBusinessObject;
ext.CustomWTPartMover.PartMover(pbo ,"GOLF_CART ","Manufacturing");
//Here GOLF_CART Target product Name & Manufacturing is my folder Name inside Target product
This my Java class called in workflow
package ext;
import wt.dataops.containermove.ContainerMoveHelper;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.fc.collections.WTValuedHashMap;
import wt.folder.Folder;
import wt.folder.FolderHelper;
import wt.inf.container.WTContainer;
import wt.inf.container.WTContainerRef;
import wt.method.RemoteAccess;
import wt.part.WTPart;
import wt.pdmlink.PDMLinkProduct;
import wt.pds.StatementSpec;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.util.WTException;
public class CustomWTPartMover implements RemoteAccess{
public static void PartMover(WTPart part,String ContainerName,String location)
{
try {
WTContainer cont=getMyProduct(ContainerName);
WTContainerRef containerRef = WTContainerRef.newWTContainerRef(cont);
Folder folder = FolderHelper.service.getFolder("/Default/"+location, containerRef);
WTValuedHashMap map = new WTValuedHashMap();
map.put(part,folder);
ContainerMoveHelper.service.moveAllVersions(map);
}
catch (WTException e) {
e.printStackTrace();
}
}
public static PDMLinkProduct getMyProduct(String ContainerName)
{
PDMLinkProduct product = null;
try {
QuerySpec qs = new QuerySpec(PDMLinkProduct.class);
qs.appendWhere(
new SearchCondition(PDMLinkProduct.class,
PDMLinkProduct.NAME, SearchCondition.EQUAL,
ContainerName), new int[] { 0 });
QueryResult qr;
qr = PersistenceHelper.manager.find((StatementSpec) qs);
while (qr.hasMoreElements()) {
product = (PDMLinkProduct) qr.nextElement();
}
} catch (WTException e) {
e.printStackTrace();
}
return product;
}
}
Hi Mani,
Thanks a lot for the guidance and extraordinary help. Although when we tried to use "ContainerMoveHelper" class, it was not found by the program. I checked and found that in 10.1, it's not there anymore. I'm trying to find out the replacement class which they have in Windchill 10.1.
Do you know which class to use instead?
Again, I really appreaciate your help on this. I owe you big
Thanks,
Wasim
Upcoming October 2019
Regional User Groups