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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

How to update WTChangeRequest2 object in windchill using java?

spatil-10-11-121
10-Marble

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 9

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

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,

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

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

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.

Hi Sumit Patil

here is the code snippet i used to change name of WTChangeRequest2 object:

public class RenameChangeRequest {

  /**

  * @param args

  * @throws WTException

  * @throws WTPropertyVetoException

  */

  public static void main(String[] args) throws WTException, WTPropertyVetoException {

  ObjectIdentifier oid = ObjectIdentifier.newObjectIdentifier("wt.change2.WTChangeRequest2:238235");

  WTChangeRequest2 cr = (WTChangeRequest2) PersistenceHelper.manager.refresh(oid);

  System.out.println("*** Change Request Name >> " + cr.getName());

  WTChangeRequest2MasterIdentity newIdentity = null;

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

  newIdentity = (WTChangeRequest2MasterIdentity) crMaster.getIdentificationObject();

  newIdentity.setName("New_Test_Name");

  IdentityHelper.service.changeIdentity(crMaster, newIdentity);

  System.out.println(" *** Done *** ");

}

}

I hope this helps you!

Regards,

Shirish

You won't be able to run this class. you need to setup a RMI Client. Have a look at:

https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS24105

Hi Shirishkumar,

     Thanks for your response, it worked for me, you made my day, thank you very very much.

Thank you

Sumit Patil

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

Announcements

Top Tags