Skip to main content
1-Visitor
September 11, 2013
Solved

FolderHelper.assignFolderByReference

  • September 11, 2013
  • 2 replies
  • 8594 views

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

Best answer by ManikandanVelay

Wasim

  1. If want to call any class in Workflow you should give fully qualified class name. for example: WTContainer -----> wt.inf.container.WTContainer
  2. doc.getContainer() will get container of your PBO
  3. For getting container by Name you have to write some QuerySpec for that.
  4. In case, If getting in situation where you need to Bulk of codes in Workflow ,better write your code into one java class file and call the same from Workflow Expression

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;

}

}

2 replies

1-Visitor
September 11, 2013

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

1-Visitor
September 11, 2013

Thanks a lot Peter. I'll give it a try and will let you know how it works.

1-Visitor
September 11, 2013

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.

1-Visitor
September 12, 2013

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

1-Visitor
September 12, 2013

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