Skip to main content
12-Amethyst
July 29, 2024
Question

How to get AffectedObjects on CustomCreateChangeNoticeFormProcessor before they persist in Database?

  • July 29, 2024
  • 1 reply
  • 687 views

Version: Windchill 12.0

 

Use Case: I want to set a lock on Change Notice creation page to check if user is adding appropriate parts


Description:

I'm using the below code to get affected objects but i'm getting list size as zero.

 

public class CustomCreateChangeNoticeFormProcessor extends CreateChangeNoticeFormProcessor {
 
@SuppressWarnings("unchecked")
public FormResult doOperation(NmCommandBean arg0, List<ObjectBean> arg1) throws WTException {
 
 
for (ObjectBean bean : arg1) {
if ((bean.getObject() instanceof WTChangeOrder2)) {
WTChangeOrder2 ecn = (WTChangeOrder2) bean.getObject();
System.out.println("ECN : " + ecn.getName());
String softTypeECN = TypeIdentifierHelper.getType(ecn).toString();
 
 
List<NmOid> affectedItemList = bean.getAddedItemsByName("changeNotice.wizardImplementationPlan.table");
System.out.println("List size 1 affected: "+affectedItemList.size());
 
List<NmOid> affectedInitialItemList = bean.getInitialItemsByName("changeNotice.wizardImplementationPlan.table");
System.out.println("List size 2 affected initial: "+affectedInitialItemList.size());
affectedItemList.addAll(affectedInitialItemList);
 
System.out.println("List size 3 total: "+affectedItemList.size());
 
for (NmOid nmo : affectedItemList) {
Object obj = nmo.getRefObject();
System.out.println("OBJ : "+ obj);
if (obj instanceof WTChangeActivity2) {
WTChangeActivity2 changeActivity = (WTChangeActivity2) obj;
 
System.out.println(changeActivity.getName()+" "+changeActivity.getName()+": Change activity found");
 
QueryResult affectedObjects = ChangeHelper2.service.getChangeablesBefore(changeActivity);
 
System.out.println("affectedObjects Size: " + affectedObjects.size());
 
 
String plannerCode="NA";
while (affectedObjects.hasMoreElements()) {
WTObject obj1 = (WTObject) affectedObjects.nextElement();
if (obj1 instanceof WTPart) {
WTPart part = (WTPart) obj1;
String partNumber = part.getNumber();
 
}
}
}
}
 
}
}
System.out.println("CreateChangeNoticeFormProcessor End");
return super.doOperation(arg0, arg1);
}
}
 

1 reply

16-Pearl
July 31, 2024

Where is the code being called from, queryresult will only find results when the CN object creation has finished

Catalina
Community Moderator
August 5, 2024

Hi @KOEL_PLM,


I wanted to see if you got the help you needed.


If so, please mark the appropriate reply as the Accepted Solution or please detail what has helped you and mark it as the Accepted SOlution. It will help other members who may have the same question.
Please note that industry experts also review the replies and may eventually accept one of them as solution on your behalf.
Of course, if you have more to share on your issue, please pursue the conversation.

Thanks,

Catalina | PTC Community Moderator