Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
package ext.training;
import ext.generic.util.IBAUtility;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.projmgmt.admin.Project2;
import wt.query.QueryException;
import wt.query.QuerySpec;
public class ModifyProjectAtt {
public static void modifyPrtAtt() throws Exception{
try {
QuerySpec qs = new QuerySpec(Project2.class);
QueryResult rs = PersistenceHelper.manager.find(qs);
while (rs.hasMoreElements()) {
Project2 proj= (Project2) rs.nextElement();
IBAUtility iba = new IBAUtility(proj);
String prdType = iba.getIBAValue("PRODUCTDEVELOPTYPE");//產品種類
if(prdType == null || prdType.trim().equals("")){}
else{
if(prdType.indexOf("類")>-1){
}else{
String corType = prdType+"類";
iba.setIBAValue("PRODUCTDEVELOPTYPE", corType);//設定新的Type名稱
iba.updateAttributeContainer(proj);//更新project
iba.updateIBAHolder(proj);
}
}
}
} catch (QueryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Hi,
Can you say version of Windchill?
I think, you can try PersistableAdapter (or depricated LWCNormalizedObject )
PersistableAdapter PObj = new PersistableAdapter(proj,null,null,null);
PObj.load("PRODUCTDEVELOPTYPE");
PObj.set("PRODUCTDEVELOPTYPE", corType);
PObj.apply();
----------------------------------
Example usage from API doc (%Windchill%\Windchill\codebase\wt\clients\library\api\com\ptc\core\lwc\server\PersistableAdapter.html):
CREATE
Locale locale = SessionHelper.getLocale(); PersistableAdapter obj = new PersistableAdapter("com.acme.AcmePart",locale,new CreateOperationIdentifier());
obj.load("name","number");
obj.set("name","my name");
obj.set("number","12345");
obj.persist();
RETRIEVE
PersistableAdapter obj = new PersistableAdapter(my_persistable,null,locale,null);
obj.load("name","number");
Object nameValue = obj.get("name");
Object numberValue = obj.get("number");
UPDATE
PersistableAdapter obj = new PersistableAdapter(my_persistable,null,locale,new UpdateOperationIdentifier());
obj.load("attributeA","attribtueB");
obj.set("attributeA",Boolean.TRUE);
obj.set("attribtueB","PURPLE");
obj.apply();
...
PersistenceHelper.manager.modify(my_persistable);
---------------------------------
Best regards
version is windchill 10.2 , runtime by workflow
Ok, use PersistableAdapter