Skip to main content
14-Alexandrite
June 15, 2018
Question

Editing Attributes on the Links of Change Relationship Tables

  • June 15, 2018
  • 2 replies
  • 6806 views

This is a topic in the Windchill Help: http://support.ptc.com/help//windchill/wc111_hc/whc_en/index.html#page/Windchill_Help_Center%2FWCCG_BusLogicCust_EditAttrChangeRelTable.html%23.

Anyone ever successfully made this customization to the Affected or Resulting objects tables on the Change Notice? I need help with the data utility.

2 replies

16-Pearl
June 19, 2018

Did you check out the Tips and Tricks from JeffZemsky

14-Alexandrite
June 22, 2018

I've gotten part of the way through this but am still having problems with the form delegate. I can enter a value in a textbox for my string attribute on the change task editing page, so it seems like my data utility is working. But once I select finish, the value entered isn't persisted back to the Change Task. I wrote a form delegate and registered it using the wt.properties property com.ptc.netmarkets.util.misc.defaultActions as described in the help. This seemed like the better-documented part of the example, but I can't get it to work.

package ext.change;

import com.ptc.windchill.enterprise.change2.forms.delegates.ChangeTaskAffectedItemsFormDelegate;
import wt.change2.ChangeItemIfc;
import wt.fc.collections.WTCollection;
import wt.util.WTException;
import com.ptc.windchill.enterprise.change2.ChangeLinkAttributeHelper;
import com.ptc.windchill.enterprise.change2.beans.ChangeLinkAttributeBean;
import wt.util.WTPropertyVetoException;
import com.ptc.core.meta.common.UpdateOperationIdentifier;
import com.ptc.core.lwc.server.PersistableAdapter;
import wt.change2.WTChangeActivity2;
import wt.change2.ChangeRecord2;
import com.ptc.windchill.enterprise.change2.ChangeManagementClientHelper;

import java.util.Iterator;

public class MyAffectedItemsFormDelegate extends ChangeTaskAffectedItemsFormDelegate {

 /**
 * This method is used to post-process attributes on the change activity
 * and change records. 
 */
	@SuppressWarnings("unchecked")
	@Override
	protected WTCollection processLinkAttributes(ChangeItemIfc item, WTCollection binaryLinks) throws WTException {
		WTCollection modifiedLinks = super.processLinkAttributes(item, binaryLinks);
		if (binaryLinks != null && !binaryLinks.isEmpty() && item instanceof WTChangeActivity2) {
		 // The link bean has knowledge of how of link attributes and supports the JCA interfaces.
		 ChangeLinkAttributeBean linkBean = ChangeLinkAttributeHelper.getChangeLinkAttributeBean();
		 linkBean.setFormData(getObjectBean());
		 for(Iterator<ChangeRecord2> iter = binaryLinks.persistableIterator(ChangeRecord2.class, true); iter.hasNext(); ) {
			ChangeRecord2 record = iter.next();
			// The getTableDataValue() will get the attribute from the FORM data supporting any specific change table handlers
			String value = ChangeLinkAttributeHelper.getTableDataValue("estimated_cost", 
					ChangeManagementClientHelper.getReference(record.getChangeable2()), linkBean);
			// The new LWC API for getting and setting attributes.
			PersistableAdapter lwc = new PersistableAdapter(record, null, null, new UpdateOperationIdentifier());
			lwc.load("estimated_cost");
			Object currentValue = lwc.get("estimated_cost");
			// Only set the attribute if it is different than the current value
			if(( value != null && currentValue != null && !value.equals(currentValue.toString())) || (value == null && currentValue != null) ) {
			 lwc.set("estimated_cost", value);
			 lwc.apply();
			 // calling apply() will require verification, however since this form delegate is setting the changes we can set it as verified.
			 try {
				record.getPersistInfo().setVerified(true);
			 } catch (WTPropertyVetoException e) {
				e.printStackTrace();
			 }
			 modifiedLinks.add(record);
			}
		 }
		}
		return modifiedLinks;
	}
}
20-Turquoise
June 22, 2018

The Windchill java docs show persisting the updated object with:

PersistenceHelper.manager.modify(my_persistable);

 

I see you using the apply() method but not persisting the updated object. Have you tried this?

lwc.set("estimated_cost", value);
lwc.apply();

PersistenceHelper.manager.modify(record);//add this?

 

 
14-Alexandrite
June 22, 2018

Thanks for the suggestion, but I'm getting the same thing - doesn't persist back to Change Task.