cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Custom Webject not working as expected

RG_10893406
7-Bedrock

Custom Webject not working as expected

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.
ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

8 REPLIES 8

 

RG_10893406_1-1721979788255.png

 

 

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

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>

Hi @RG_10893406,


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


If so, please mark the appropriate reply 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

I did not get any solution. I am still searching for the solution.

Please let me know if anybody aware of it. It will be helpful for me.

If it helps you solve it, they asked to see the webject but what you sent is the code which implements an info engine task to call the webject. You need to show java code the webjects

Please check the below java code
 
public class ExampleCustomWebject {
 
private static WTPart part = null;
 
private static Vector getColumnElements(Task task) throws IEException {
Webject w = task.getWebject();
String grp_out = null;
String column = null;
String grp_in = null;
Group group_in = null;
 
Param param = w.getParam("COLUMN");
if (param == null)
throw new GroupWebjectException("ExampleCustomWebject: no COLUMN");
 
column = param.getData();
 
param = w.getParam("GROUP_IN");
if (param == null)
group_in = task.getGroupIn();
else
group_in = task.getVdb(param.getData());
if (group_in == null)
throw new GroupWebjectException("ExampleCustomWebject: no GROUP_IN");
 
int element_count = group_in.getElementCount();
Vector elements = new Vector();
for (int i = 0; i < element_count; i++) {
Element e = group_in.getElementAt(i);
 
Vector ev = e.getValues(column, true);
 
if (ev == null)
continue;
 
for (int j = 0; j < ev.size(); ++j)
elements.addElement(ev.elementAt(j));
}
if (!(elements.size() > 0))
throw new GroupWebjectException("ExampleCustomWebject: no COLUMN \"" + column + "");
 
return elements;
}
 
public static Task contextName(Task task) throws IEException {
// public static List<Task> contextName(Task task) throws IEException {
System.out.println("Inside getContextName() " + task.getName());
try {
Object val;
String objId = "";
String grp_out = null;
String column = null;
String contextName = "";
List<String> finalContext = new ArrayList<>();
Task response = new Task();
// List<Task> response = (List<Task>) new Task();
Webject w = task.getWebject();
System.out.println("Group_IN name " + w.getGroupInName());
System.out.println("Group_Out name " + w.getGroupOutName());
System.out.println("Webject name " + w.getName());
Param param = w.getParam("GROUP_OUT");
System.out.println("Param Value " + param.getName());
System.out.println("Param Value " + param.getData());
if (param == null)
throw new GroupWebjectException("contextName: no GROUP_OUT");
grp_out = param.getData();
param = w.getParam("COLUMN");
if (param == null)
throw new GroupWebjectException("contextName: no COLUMN");
column = param.getData();
System.out.println("column " + param.getData().toString());
Vector elements = getColumnElements(task);
System.out.println("elements " + elements.size());
for (Enumeration en = elements.elements(); en.hasMoreElements();) {
val = en.nextElement();
System.out.println("Value " + val.toString());
objId = val.toString();
String[] parts = objId.split(":");
if (parts.length >= 3) {
String result = parts[0] + ":" + parts[1] + ":" + parts[2]; // VR:wt.part.WTPart:2132727
System.out.println(result);
contextName = getContexttName(result);
System.out.println("Context Name is " + contextName);
finalContext.add(contextName);
System.out.println("finalContext " + finalContext.size());
}
}
com.infoengine.object.factory.Element elem = new com.infoengine.object.factory.Element();
Att att = new Att(column + "ContextName");
att.addValue("" + finalContext);
System.out.println("ATT " + att.toString());
elem.addAtt(att);
System.out.println("element " + elem.getName());
Group group_out = new Group(grp_out);
group_out.setElement(elem);
System.out.println("group_out " + group_out.getStatus());
System.out.println("group_out to string " + group_out.toString());
 
response.addVdb(group_out);
return response;
} catch (Exception exc) {
exc.printStackTrace(System.err);
if (exc instanceof IEException)
throw (IEException) exc;
throw new IEInternalServiceException(exc);
}
}
 
private static String getContexttName(String obid) throws WTException {
ReferenceFactory rf = new ReferenceFactory();
WTReference reference = (WTReference) rf.getReference(obid);
Persistable pers = (Persistable) reference.getObject();
String newName = "";
if (pers instanceof WTPart) {
newName = ((WTPart) pers).getContainerName();
}
return newName;
}
 
}

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


Top Tags