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

Editing Attributes on the Links of Change Relationship Tables

Level 7

Editing Attributes on the Links of Change Relationship Tables

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_....

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

8 REPLIES 8

Re: Editing Attributes on the Links of Change Relationship Tables

Did you check out the Tips and Tricks from JeffZemsky

Re: Editing Attributes on the Links of Change Relationship Tables

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

Re: Editing Attributes on the Links of Change Relationship Tables

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?

 

 

Re: Editing Attributes on the Links of Change Relationship Tables

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

Re: Editing Attributes on the Links of Change Relationship Tables

It never enters the for loop. Note sure why. The size of the binaryLinks WTCollection is not zero during my test. No ChangeRecord2?

Re: Editing Attributes on the Links of Change Relationship Tables

If there is an issue with this documentation please raise a call with Technical Support so it can be corrected.

Re: Editing Attributes on the Links of Change Relationship Tables

I've found several small mistakes in the documentation, but it's really the lack of detail that is the problem. I have a TS case open but haven't received much help. The documentation also uses some deprecated code and hasn't changed for many years, even though the API has.

Re: Editing Attributes on the Links of Change Relationship Tables

Please send me the call number