This would work but another option for less effort could be to extend the already existing ObjectWebject class that already has that function. In the example below you can use getUfidsAsGroup then loop through the group and perform actions on each element, like get the context just for an example, then add to the group_out.
Task:
<%@page language="java" session="boolean" access="http|soap|internal"%>
<%@taglib uri="http://www.ptc.com/infoengine/taglib/core" prefix="ie"%>
<!--
deploy: WT_HOME\tasks\Query-ExampleWebject.xml
usage http://host/Windchill/servlet/IE/tasks/Query-ExampleWebject.xml
-->
<%
String wcAdapter = wt.util.WTProperties.getLocalProperties().getProperty("wt.federation.ie.VMName");
%>
<ie:webject name="Query-Objects" type="OBJ">
<ie:param name="INSTANCE" data="<%=wcAdapter%>"/>
<ie:param name="WHERE" data="number=GC00000*"/>
<ie:param name="attribute" data="number" delim="," />
<ie:param name="type" data="wt.part.WTPart" />
<ie:param name="group_out" data="parts" />
</ie:webject>
<ie:webject name="EXAMPLE" type="OBJ">
<ie:param name="group_in" data="parts" />
<ie:param name="INSTANCE" data="<%=wcAdapter%>"/>
<ie:param name="group_out" data="partsWithContext" />
</ie:webject>
Webject:
public class Example_QueryWebject extends ObjectWebject {
public Task invoke(Task task) throws WTException {
Webject webject = task.getWebject();
Task response = new Task();
String groupOutName = null;
try {
groupOutName = webject.paramValue("GROUP_OUT");
if (StringUtils.isBlank(groupOutName)) {
throw new WTException("Error: GROUP_OUT is null");
}
Group group = new Group(groupOutName);
Group g = getUfidsAsGroup(task);
List<Element> strings = g.getElementList();
group.setClassName("String");
ReferenceFactory rf = new ReferenceFactory();
for (Element element : strings) {
// Retrieve ufid for element
String obidAttribute = element.getUfid();
// Check if the "obid" attribute exists
if (obidAttribute != null) {
// Print the content of the "obid" attribute
obidAttribute = obidAttribute.substring(0,obidAttribute.lastIndexOf(':'));
WTReference ref = rf.getReference(obidAttribute);
WTPart part = (WTPart)ref.getObject();
if (part == null) {
throw new WTException("could not be retrieved for OBID=" + obidAttribute);
}
this.setAttributes(part, group);
} else {
System.out.println("obid attribute not found in element.");
}
}
response.addVdb(group);
} catch (Exception var10) {
var10.printStackTrace();
Group errorGroup = new Group(groupOutName);
errorGroup.setClassName(this.groupOutClass);
Element errorElement = new Element();
errorElement.addAtt(new Att("wiState", "Error: " + var10.getLocalizedMessage()));
errorGroup.addElement(errorElement);
response.addVdb(errorGroup);
System.out.println("\n" + response.getVdb().toXML());
}
return response;
}
private void setAttributes(WTPart part, Group group) throws WfException, WTException {
Element ele = new Element();
ele.addAtt(new Att("Name", part.getName()));
ele.addAtt(new Att("Number", part.getNumber()));
ele.addAtt(new Att("Context", part.getContainerName()));
group.addElement(ele);
}
}
site.xconf:
<Property name="EXAMPLE.WCTYPE|java.lang.Object" overridable="true"
targetFile="codebase/wt.adapter.delegates.properties"
value="ext.Example_QueryWebject"/>