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

dmcalister-2
13-Aquamarine

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.

12 REPLIES 12
lgrant
14-Alexandrite
(To:dmcalister-2)

Did you check out the Tips and Tricks from JeffZemsky

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

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?

 

 

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

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

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.

Please send me the call number

MSuarez
6-Contributor
(To:JeffZemsky)

Hi Jeff,

 

I'm hanging in the same problem. 
was the API Doc fixed?

 

Best Regards

M.Suarez

MSuarez
6-Contributor
(To:MSuarez)

Actually a little bit of details.
I have a working datautility on my change record.

MSuarez_0-1585605075390.png

But in my custChangeTaskResultingItemsFormDelegate in the processLinkAttributes() I don't get a value back.

String value = ChangeLinkAttributeHelper.getTableDataValue(internalname of attribute in ChangeRecord, ChangeManagementClientHelper.getReference(record.getChangeable2()), linkBean);

it supposes to work as the example in the documentation.

 

Has someone on the thread engaged Tech Support.  If so would you PM me your Call # please?

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

it seems that the if clause is wrong. The combination "value != null && currentValue == null" is missing. Adding this worked for me.

Announcements