Skip to main content
1-Visitor
Mar 1, 2017 2:39 AM UTC
Question

How to update WTChangeRequest2 object in windchill using java?

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();

  }

9 replies

2-Explorer
Mar 2, 2017 3:58 AM UTC

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

Translate
1-Visitor
Mar 3, 2017 10:37 PM UTC

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,

Translate
ShirishMorkhade
16-Pearl
Mar 8, 2017 6:13 PM UTC

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

Translate
1-Visitor
Mar 10, 2017 6:00 AM UTC

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

Translate
17-Peridot
Mar 13, 2017 7:27 AM UTC

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.

Translate
1-Visitor
Mar 13, 2017 12:32 PM UTC

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) );

Translate