Skip to main content
7-Bedrock
July 26, 2024
Solved

Custom Webject not working as expected

  • July 26, 2024
  • 1 reply
  • 2079 views
I am using Windchill PDMLink Release 12.1 and Datecode with CPS 12.1.2.0

I have created two webjects one is Search-Objects and another is custom webject. I'm passing the object id to the custom webject as input and I am getting the actual value as a output. But the issue is, in the output result only for the last object the custom value is showing not for others.
    Best answer by rhart

    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"/>

    1 reply

    7-Bedrock
    July 26, 2024

     

    RG_10893406_1-1721979788255.png

     

     

    14-Alexandrite
    July 27, 2024

    @RG_10893406.. can you upload the two webjects you are using?

    7-Bedrock
    July 29, 2024

    From Search-Objects webject im getting the parts details, and Context-Name Webject is the custom webject which we have created. Using Return-Group webject im combining both webject data. But the data is not combining. The custom data is showing for only the last object.

     

    <%@page language="java"%>
    <%@taglib uri="http://www.ptc.com/infoengine/taglib/core" prefix="ie"%>

    <ie:webject name="Search-Objects" type="OBJ">
    <ie:param name="INSTANCE" data="$(@FORM[]supporting-adapter[*])" delim="!" valueSeparator="!" default="<%=com.infoengine.au.NamingService.getVMName()%>"/>
    <ie:param name="TYPE" data="wt.part.WTPart"/>
    <ie:param name="attribute" data="obid,number,name,version,lifeCycleState,containerReference" delim=","/>
    <ie:param name="GROUP_OUT" data="objectSearched"/>
    </ie:webject>

    <ie:forEach groupIn="objectSearched" groupOut="Obj">
    <ie:webject name="Context-Name" type="EXT" use="ext.customWebject.ExampleCustomWebject">
    <ie:param name="COLUMN" data="obid"/>
    <ie:param name="GROUP_IN" data="Obj"/>
    <ie:param name="GROUP_OUT" data="ActualResult"/>
    </ie:webject>
    </ie:forEach>

    <ie:webject name="Return-Groups" type="GRP">
    <ie:param name="GROUP_IN" data="objectSearched"/>
    <ie:param name="GROUP_IN" data="ActualResult"/>
    </ie:webject>