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.

How to change my customized attribute of EPMDocutment by API?

WhiteChen
5-Regular Member

How to change my customized attribute of EPMDocutment by API?

I want to use API  to change my customized attribute of EPMDocument, the attribute setting in Utility  as attachment show. Who can help me?

Always failed, the error info is:

Exception in thread "main" java.lang.reflect.InvocationTargetException

  at wt.method.RemoteMethodServer.invoke(RemoteMethodServer.java:795)

  at com.cisco.whichen2.SetEPMAttribute.main(SetEPMAttribute.java:47)

Caused by: com.ptc.core.meta.container.common.ConstraintException: The value for TestWhichen cannot be changed.

  ... 2 more

code:

public static void setEPMAttribute(EPMDocument epm, String attribute,

  String value) throws Exception {

  PersistableAdapter obj = new PersistableAdapter(epm, null,

  java.util.Locale.US,

  new com.ptc.core.meta.common.DisplayOperationIdentifier());

  obj.load(attribute);

  obj.set(attribute, value);

  obj.apply();

  PersistenceHelper.manager.modify(epm);

  }

6 REPLIES 6

Hi Chen,

1. We generally recommend to use EPMWorkspaceManager::setAttributes(), in a workspace contex, to modify the EPMDocument attributes.

You can find some snippet code in article CS110292.

2. Are you able to modify this attribute on this CAD document from the UI ? For example if the CAD document is a family table (FT) instance and if the attribute is not a column of the FT, you can modify it on the generic objkect only (code or UI).

3. About the PersistableAdapter, you should probably use the ChangeOperationIdentifier instead of DisplayOperationIdentifier for update operation.

WhiteChen
5-Regular Member
(To:smainente)

Hi Stephane,

Thanks for your reply.

1.I want to modify epmducoment after querying currently. But modifying in workspace context is another requirement.

2.I can modify the attribute from UI.

3.I use ChangeOperationIdentifier instead of DisplayOperationIdentifier, I can modify the check-out epmdocument now. But I want to modify attribute when  epmdocument is check-in. Can I do that? If yes, could you please introduce how to realize it?


Thanks.

White

You cannot modify a CAD document attribute without iterating it in the process (via check-out/check-in). If the attribute value is common to all the iterations of the CAD document you can maybe add it to the EPMDocumentMaster - you will be able to modify it without performing a CO/CI - but I'm not sure how it will be handled by the UI. Regards, Stéphane

The method which you are trying to execute is a server only method and should be run from the server side - either using a workflow or using remote server invocation here is an example - https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS24105

Also make sure you update a checked out(WIP) copy of the object or else you will not be able to persist it. Use workinprogresshelper to check out the file.

WhiteChen
5-Regular Member
(To:BineshKumar1)

Hi Binesh,

Thanks for your reply.

I had executed the method from sever side, it maybe not the problem you mentioned. 

Class<?> argTypes[]={EPMDocument.class, String.class,String.class};

  Object argValues[]={

  latest,

  "TestWhichen",

  "29-102079-01"

  };

  rms.invoke("setEPMAttribute", CadDocManager.class.getName(), null, argTypes, argValues);

I was onto the very same issue couple weeks ago for like 4 days straight. Didn't make it work. It's way too much beating of the code. Wish someone just documented how it's done. I doubt PersistableAdapter class is the way to do it. The help docs just speak, as always, in way too broad terms and for that reason are missleading.

Top Tags