Skip to main content
1-Visitor
May 8, 2015
Question

Get IBA value of Distribution Target in Resulting Objects column

  • May 8, 2015
  • 5 replies
  • 2903 views

Hi,

I want to add one custom column name distribution target. How can I read the values of Distribtuion Target name from WTParts details page and put it into the custom column?

Any Idea..?

Thanks,

Sakil

5 replies

BenPerry
15-Moonstone
May 8, 2015

Sakil,

I have recently obtained some help to associate all WTParts in the Resulting Objects to a particular DT. My code is below. You might find what you're looking for in here. It contains much more import statements than you need becuase this is just one method in my class. But better too much than not enough. You can remove the ones you don't need.

For example, you might be looking for:

System.out.println("\"" + part.getNumber() + "\" must already be associated with the \"" + target.getName() + "\" Distribution Target");

Full code:

package ext;

import com.ptc.windchill.esi.tgt.ESITarget;

import com.ptc.windchill.esi.tgt.ESINoSuchTargetException;

import com.ptc.windchill.esi.tgt.ESITargetUtility;

import java.io.PrintStream;

import java.text.MessageFormat;

import java.util.ArrayList;

import java.util.List;

import wt.change2.ChangeHelper2;

import wt.change2.WTChangeOrder2;

import wt.epm.EPMDocument;

import wt.fc.Persistable;

import PersistenceHelper;

import wt.fc.QueryResult;

import wt.fc.WTObject;

import wt.part.WTPart;

import wt.query.QuerySpec;

import wt.query.SearchCondition;

import wt.session.SessionHelper;

import wt.util.WTException;

import wt.util.WTPropertyVetoException;

import wt.vc.VersionIdentifier;

import wt.vc.Versioned;

public class WorkflowUtilities

{

public static void assignDT(WTChangeOrder2 cn, String dtNumber) throws WTException {

// Get target (by number) that you want to associate the WTPart to (example: "4" for "DT_NAME")

ESITargetUtility targetUtility = new ESITargetUtility();

ESITarget target = new ESITarget();

try {

target = targetUtility.getTarget(dtNumber, ((wt.inf.container.WTContained)cn).getContainerReference());

} catch (ESINoSuchTargetException e) {

e.printStackTrace();

}

// Get a list of the Resulting Objects of the Change Notice

QueryResult qr = wt.change2.ChangeHelper2.service.getChangeablesAfter(cn);

// Loop through the Resulting Objects and if it is a WTPart, and if it isn't associated to the DT, then associate to the DT

System.out.println("\n\nAttempting to assign WTParts to the \"" + target.getName() + "\" Distribution Target...");

while (qr.hasMoreElements()) {

WTObject obj = (WTObject)qr.nextElement();

if (obj instanceof WTPart) {

WTPart part = (WTPart)obj;

if(!com.ptc.windchill.esi.tgt.ESITargetUtility.isTargetAssociated(part, target)){

com.ptc.windchill.esi.svc.ESIHelper.service.assignTarget(part, target);

System.out.println("\"" + part.getNumber() + "\" has just been associated with the \"" + target.getName() + "\" Distribution Target right now");

} else {

System.out.println("\"" + part.getNumber() + "\" must already be associated with the \"" + target.getName() + "\" Distribution Target");

}

}

}

System.out.println("Done attempting to assign WTParts to the \"" + target.getName() + "\" Distribution Target.\n\n");

}

BenPerry
15-Moonstone
May 8, 2015

Sakil,

On 2nd thought, you might not be able to use this exactly. But you I hope that you'll be able to find what you're looking for in the JavaDoc under com.ptc.windchill.esi.tgt.ESITargetUtility

sahmed1-VisitorAuthor
1-Visitor
May 14, 2015

Hi Ben,

Thanks for your solution. This is to update distribution target of all the parts present in the table. But in my case I have toPTC_Case.PNG update , only for those parts, I have selected . How can I check which parts I have selected in the resulting objects table??

Thanks,

Sakil