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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

get-contentitems windchill Webject query

sudheer.raju
1-Newbie

get-contentitems windchill Webject query

All,
I am looking for a Windchill Info*Engine webject task to get the content (using get-contentitems)of the WTDocument.
What I am exactly looking is a query to return the actual file (the primary content) or any attached file.
I am using Windchill 9.0, I tried the examples given in the WCAdapterGuide, but it didn't work.
So I thought I shall check with the experts here before spending too much time doing R&D on it.

Any help is highly appreciated.


--
Sudheer

2 REPLIES 2

Sudheer, can you use Java?

Here's a webject that will get you the URL. You want the urlLocation value. To make sure you have the primary content, check isPrimary = true, otherwise the record you're looking at may be a secondary attachment:

<%@page language="java"%>
<%@taglib uri=" prefix="ie"%>

<%
String obid = (String)getContextGroup("FORM").getAttributeValue(0,"obid");

//get the windchill instance
String windchill = wt.util.WTProperties.getLocalProperties().getProperty("wt.federation.ie.VMName");
%>
<ie:webject name="List-ContentItems" type="OBJ">
<ie:param name="instance" data="&lt;%=windchill%">" valueSeparator=";" delim=";" default="windchill"/>
<ie:param name="object_ref" data="&lt;%=obid%">" delim=","/>
<ie:param name="attribute" data="*"/">
<ie:param name="group_out" data="contentItems" default="output"/">
</ie:webject>

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


Here's some Java to wrap this with, if it's useful to you:
public static String getContentUrl(String obid) {
// Fire task to grab attachments
try {
Task theTask = new Task("/getContentInfo.xml");
theTask.addParam("obid", obid);
theTask.invoke();

// Get the group out of the response
Group contentItems = theTask.getGroup("contentItems");

// Loop through the results until you find a urlLocation
int count = contentItems.getElementCount();
for (int i = 0; i < count; i++) {
Boolean isPrimary = Boolean.valueOf((String) contentItems.getAttributeValue(i, "isPrimary"));
if (isPrimary != null && isPrimary.booleanValue()) {
String contentURL = (String) contentItems.getAttributeValue(i, "urlLocation");
if (contentURL != null)
return contentURL;
}
}
} catch (IEException e) {
System.err.println("Error executing getContentInfo.xml webject.");
log.error(e.getMessage(), e);

} catch (IOException e) {
System.err.println("Error accessing getContentInfo.xml webject.");
log.error(e.getMessage(), e);
}

return null;
}

Once you do all that, you should be able to just download the file using an HttpClient, something along the lines of this:
HttpClient client = new HttpClient();
client.getState().setCredentials(
new AuthScope("windchill.mycompany.com", 80),
new UsernamePasswordCredentials("username","password"));

get = new GetMethod(getContentUrl(obid));
get.setDoAuthentication(true);

client.executeMethod(get);
byte[] documentBytes = get.getResponseBody();

get.releaseConnection();

-Thomas R. Busch
Sr. Software Developer
Stryker Instruments
(269) 323-7700 x4014
tom.busch@stryker.com<">mailto:tom.busch@stryker.com>

Thanks Thomas for the suggestion.

I shall for once try the way you suggested and will update you.

Is there a way that I just use the I*E Webject to get the content (physical file, be it primary or secondary) by passing the OBID to the OBJECT_REF param (<ie:param name="OBJECT_REF" data="&lt;%=obid%">">), and then the file gets stored in any physical location I provide in STAGING_AREA (<ie:param name="STAGING_AREA" data="pathname"/">, the documentation states that).

What I am exactly looking is that if I can get this content (just by using I*E Webject query) stored on a physical location (say temp directory) so that I can pass it to a external system (application).

--
Sudheer

Top Tags