cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

We are happy to announce the new Windchill Customization board! Learn more.

FolderHelper.assignFolderByReference

ptc-4819768
1-Newbie

FolderHelper.assignFolderByReference

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

1 ACCEPTED SOLUTION

Accepted Solutions

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;

}

}

View solution in original post

15 REPLIES 15

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

  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;

}

}

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

Hi Mani,

The error got resolved as

the reason was:

In Windchill 9.1, the class ContainerMoveHelper.class is located in codebase\wt\dataops\containermove

In Windchill 10.1, it is in codebase\WEB-INF\lib\wncWeb.jar

I added codebase\WEB-INF\lib\wncWeb.jar in classpath for the project in Eclipse and it resolved the above mentioned error.

However, now I have issues with WTContainerRef containerRef = WTContainerRef.newWTContainerRef(cont);

On hover, it says: "The type com.ptc.windchill.annotations.metadata.ColumnType cannot be resolved. It is indirectly referenced from required .class files"

I even tried to modify the method with another method:

public static PDMLinkProduct getMyProduct(String ContainerName) throws WTException {

PDMLinkProduct product = null;

QuerySpec qs = new QuerySpec(PDMLinkProduct.class);

SearchCondition sc = new SearchCondition(PDMLinkProduct.class, PDMLinkProduct.NAME, SearchCondition.EQUAL, ContainerName);

qs.appendSearchCondition(sc);

QueryResult qr = PersistenceHelper.manager.find(qs);

if(qr.hasMoreElements())

product = (PDMLinkProduct) qr.nextElement();

return product;

}

But it says appendSearchCondition is deprecated.

Any more help please.

Thanks,

Wasim

KD
4-Participant
4-Participant
(To:ptc-4819768)

Hi Wasim,

Use qs.appendWhere(sc,new int[]{ 0 }); and cast qs with (StatementSpec) when you are using Persistencehelper.manager.find

To get container reference from WTContainer you can use cont.getContainerReference(); also.

Thanks and Regards,

Kaushik

Message was edited by: kaushik das

ptc-4819768
1-Newbie
(To:KD)

Hi Kaushik,

I've had a little success with the below mentioned code:

public class CustomWTPartMover implements RemoteAccess{

public static void PartMover(WTPart part)

{

System.out.println("try started");

try {

ObjectIdentifier oid2 = ObjectIdentifier.newObjectIdentifier("wt.pdmlink.PDMLinkProduct:12551258277");

System.out.println(" My Product Found");

PDMLinkProduct product = (PDMLinkProduct) PersistenceHelper.manager.refresh(oid2);

System.out.println("Product Refreshed");

Folder folder = FolderHelper.service.getFolder("/Default/NewPart", (WTContainerRef)product.getContainerReference());

System.out.println("Folder Found");

FolderHelper.service.changeFolder((FolderEntry)part, folder);

/*

WTValuedHashMap map = new WTValuedHashMap();

map.put((FolderEntry)part,folder);

System.out.println("Folder mapped");

ContainerMoveHelper.service.moveAllVersions(map);

*/

System.out.println("Change Folder successfully!!!!!");

}

catch (WTException e) {

e.printStackTrace();

}

}}

The problem is, the program doesn't recognize the Product, instead move the object to Organization/Folders. Any help here?

Thanks,

Wasim

KD
4-Participant
4-Participant
(To:ptc-4819768)

Hi Wasim,

Try this code to fetch the PDMLinkProduct object.

ReferenceFactory factory = new ReferenceFactory();

ObjectReference objRef = (ObjectReference)factory.getReference("OR: wt.pdmlink.PDMLinkProduct:162524”);

PDMLinkProduct product=(( PDMLinkProduct) objRef.getObject());

Regards,

Kaushik

ptc-4819768
1-Newbie
(To:KD)

Hi Kaushik,

Even this code can't fetch the Product. It still moves the object to Organization folder.

Could you please advice?

Thanks,

Wasim

Thanks Mani. Finally the code is working. Thanks a lot for your help.

The minor change which I made to your code was:

map.put((FolderEntry)part,folder);

Top Tags