Skip to main content
1-Visitor
March 1, 2017
Question

How to update WTChangeRequest2 object in windchill using java?

  • March 1, 2017
  • 3 replies
  • 4751 views

Hi,

     this is my code, i want to update the attributes of the wt.change2.WTChangeRequest2 of existing objects,

Thank you in advance.

wt.change2.WTChangeRequest2 doc = null;

  try {

  wt.fc.ObjectIdentifier oid = wt.fc.ObjectIdentifier

  .newObjectIdentifier("wt.change2.WTChangeRequest2:15971");

  doc = (wt.change2.WTChangeRequest2) wt.fc.PersistenceHelper.manager

  .refresh(oid);

  System.out.println(doc.getName());

  } catch (Exception e) {

  // TODO: handle exception

  e.printStackTrace();

  }

3 replies

1-Visitor
March 2, 2017

If you are trying to set out of the box change attributes, you can set it using the below methods

setName, setNumber,setCategory, setComplexity, setDescription, setProposedSolution, setRequestPriority, setReviewDescription

If you are trying to update a custom attribute, use this API http://support.ptc.com/cs/wncdoc/102/wcapi/com/ptc/core/lwc/server/PersistableAdapter.html

If you are on Windchill 11, PTC introduced a new API for this http://support.ptc.com/cs/wncdoc/110/wcapi/com/ptc/core/businessfield/server/businessObject/BusinessObjectHelper.html

1-Visitor
March 3, 2017

Hi

If you are familiar with Info Engine tasks you can use them too to update your Change Object. Be carful that the change objects can get versioned so be sure to target the exact version.

Regards,

16-Pearl
March 8, 2017

Hi Sumit Patil‌,

If you wish you update IBA attribute of wt.change2.WTChangeRequest2 of existing objects, then you can use PersistableAdapter API as Binesh Kumar suggest.

However if you wish to update name/number, you need use <Object_Type>MasterIdentity API, for example: WTChangeRequest2MasterIdentity.

please refer to below code snippet:

WTChangeRequest2MasterIdentity newIdentity = null;

WTChangeRequest2Master crMaster = (WTChangeRequest2Master)cr.getMaster();

newIdentity = (WTChangeRequest2MasterIdentity) crMaster.getIdentificationObject();

newIdentity.setName("New_Test_Name");

IdentityHelper.service.changeIdentity(crMaster, newIdentity);

I hope this helps you.

Regards,

Shirish

1-Visitor
March 10, 2017

Hi Shirishkumar,

     Thank you for your response, and sorry for late reply,

In my code, I am updating the name, folder path and the organization, so in this, my object is updating the organization and the folder path but, it is giving an exception for name. I am getting this,

The operation:   "changeIdentity" failed.

Nested exception is: wt.util.WTRemoteException: Unable to invoke remote method

Could you suggest me for this why it giving an exception

Thank you

Sumit

17-Peridot
March 13, 2017

I guess the problem starts earlier. Does your class implements RemoteAccess? Normally your this exception is thrown when you forget to implement this class, so the invoke doesn't work.

1-Visitor
March 13, 2017

UPDATE

final Locale locale = SessionHelper.getLocale();

final UpdateOperationIdentifier updateOperationId = new UpdateOperationIdentifier();

final BusinessObjectHelper busObjHelper = BusinessObjectHelperFactory.getBusinessObjectHelper();

final List busObjs =
busObjHelper.newBusinessObjects( locale, updateOperationId, true, persistables );
busObjHelper.load( busObjs, businessFields );
for ( BusinessObject aBusObj : busObjs ) {
for ( BusinessField aBusinessField : businessFields ) {
aBusObj.set( aBusinessField, theValueForTheField );
}
}
final List modifiedPersistables = busObjHelper.apply( busObjs );
...
PersistenceHelper.manager.modify( new WTArrayList(modifiedPersistables) );