Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
Hi Folks,
Anyone know of a way to create link to the highest version of a primary content file?
If not, how about a static link to the object itself?
Perhaps post a link on a document:
Create a JSP page that accepts a parameter (docNumber). Then it has to get the latest version (Released for Production) of the document by querying, from a URL for the information page and forward it to that URL.
I have same kind of requirement. referred an article but it is for WC 10.0.
https://www.ptc.com/en/support/article?n=CS70348
If anybody have idea please help
Hi @mpalanisamy1,
You can use Info Engine task and Get-ContentItems to get the content and create the URL link as follows, it will get the latest document using Search-Object and then the content.
http://localhost/Windchill/servlet/IE/tasks/ext/getdoccontent.xml?where=(number='0000000041')
You can check the following code for reference, though I haven't tested it thoroughly.
<%@page language="java"%> <%@page import="wt.fc.*"%> <%@page import="wt.util.WTException"%> <%@page import="wt.adapter.*"%> <%@page import="wt.content.ApplicationData"%> <%@page import="wt.content.ContentServerHelper"%> <%@page import="wt.epm.EPMDocument"%> <%@page import="wt.content.ContentItem"%> <%@page import="wt.content.FormatContentHolder"%> <%@page import="wt.content.ContentServerHelper"%> <%@page import="wt.content.ContentHelper"%> <%@taglib uri="http://www.ptc.com/infoengine/taglib/core" prefix="ie"%> <% String adapter = wt.util.WTProperties.getLocalProperties().getProperty("wt.federation.ie.VMName"); %> <ie:webject name="Search-Objects" type="OBJ"> <ie:param name="ATTRIBUTE" data="name,number" delim=","/> <ie:param name="INSTANCE" data="<%= adapter %>"/> <ie:param name="ITERATION" data="LATEST"/> <ie:param name="TYPE" data="wt.doc.WTDocument"/> <ie:param name="VERSION" data="LATEST"/> <ie:param name="WHERE" data="${@FORM[]where[]}"/> <ie:param name="GROUP_OUT" data="cad"/> </ie:webject> <ie:webject name="Query-Objects" type="OBJ"> <ie:param name="INSTANCE" data="<%= adapter %>"/> <ie:param name="TYPE" data="wt.content.HolderToContent"/> <ie:param name="WHERE" data="theContentHolder=${cad[]obid[]}"/> <ie:param name="ATTRIBUTE" data="theContentItem,obid" delim=","/> <ie:param name="GROUP_OUT" data="cont"/> </ie:webject> <ie:webject name="Query-Objects" type="OBJ"> <ie:param name="INSTANCE" data="<%= adapter %>"/> <ie:param name="TYPE" data="wt.content.ApplicationData"/> <ie:param name="object_ref" data="${cont[*]theContentItem[]}" delim=";" valueSeparator=";"/> <ie:param name="ATTRIBUTE" data="fileName,role,obid" delim=","/> <ie:param name="GROUP_OUT" data="appdata"/> </ie:webject> <% //handling multi-attachment getting only primary Group myGroupD = getGroup("appdata"); Enumeration elementsC = myGroupD.getElements(); while( elementsC.hasMoreElements() ) { Element elementC = (Element) elementsC.nextElement(); String role = elementC.getAtt("role").getValue().toString(); if(role.equals("PRIMARY") ) { String obid = elementC.getAtt("obid").getValue().toString(); %> <ie:webject name="Get-ContentItems" type="OBJ"> <ie:param name="INSTANCE" data="<%= adapter %>"/> <ie:param name="TYPE" data="wt.content.ApplicationData"/> <ie:param name="object_ref" data="<%= obid %>"/> </ie:webject> <% } } %>
Regards,
Bhushan
Thanks Bushan.
It is not creating URL link for one document. For all WT Documents it should create automatically
Thanks
Mohana
Hi Mohan, @mpalanisamy1
I understand, but once you have the task file saved. The URL can be created for any document (or all documents) by just replacing the document number, it should not be a big task.
http://localhost/Windchill/servlet/IE/tasks/ext/getdoccontent.xml?where=(number='0000000041')
Regards,
Bhushan
I am working on a JSP page but I think the basics are covered. I would really like to extend to Secondary content and plot/PDF files in the representation but I thought I should share this. Drop into content folder under netmarkets/jsp folder. Secondary content might not work since you can have a number of secondary content and which one do you send. I am not about to add a zip it routine to this so I might give on that. K.I.S.S.
Right now, this is only working primary content on WTDocuments and have not tested it with EPMDocuments.
<%--
Document : ContentDownload
Created on : April 1,2019
Author : antonio.villanueva
--%>
<%@ page import="wt.fc.*,wt.vc.*,wt.epm.*,wt.query.*,wt.vc.views.*,wt.content.*,wt.vc.config.*,wt.doc.*,com.ptc.netmarkets.util.beans.NmCommandBean,java.util.*,wt.util.*"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%--
This JSP page returns file content from PDMLink documents using static URL.
NUMBER: WTDocument Number
TYPE:WTDocument or EPMDocument (Not yet Implemented)
SOURCE: primary, secondary, or wvs (Not yet Implemented)
VERSION: Version letter in PDMLink
Assumption that latest iteration is required.
--%>
<%
//1. Obtain request parameters
ReferenceFactory rf = new ReferenceFactory();
String number = request.getParameter("number");
String version = request.getParameter("version");
String source = request.getParameter("source");
String type = request.getParameter("type");
//2. Validate inputs
boolean validInputs=true;
String message=new String();
if ((number == null) || (number.equals("")))
{
validInputs=false;
message="Missing required number parameter.<br>\n";
}
if ((source == null) || (source.equals("")))
{
source="WTDocument";
}
else if (!((source.equals("WTDocument"))||(source.equals("EPMDocument"))))
{
validInputs=false;
message=message+"Invalid source parameters (WTDocument or EPMDocument).<br>\n";
}
if ((type == null) || (type.equals("")))
{
type="PRIMARY";
}
else if (!((type.equals("PRIMARY"))||(type.equals("SECONDARY"))||(type.equals("WVS"))))
{
validInputs=false;
message=message+"Invalid type parameters (PRIMARY or SECONDARY or WVS).<br>\n";
}
//3. Proceed with getting URL is valid inputs
boolean validOutput=true;
if (validInputs)
{
String url = null;
if (source.equals("WTDocument"))
{
QuerySpec qs = new QuerySpec(WTDocumentMaster.class);
qs.appendWhere(new SearchCondition(WTDocumentMaster.class,WTDocumentMaster.NUMBER,SearchCondition.EQUAL, number));
QueryResult qr = PersistenceHelper.manager.find(qs);
if(qr.hasMoreElements())
{
WTDocumentMaster docm = (WTDocumentMaster) qr.nextElement();
QueryResult qrLatest = VersionControlHelper.service.allVersionsOf(docm);
while(qrLatest.hasMoreElements())
{
WTDocument doc = (WTDocument) qrLatest.nextElement();
if (version!= null)
{
if (!(doc.getVersionIdentifier().getValue().equals(version)))
continue;
}
ContentHolder ch = (ContentHolder)ContentHelper.service.getContents(doc);
if (type.equals("PRIMARY"))
{
ApplicationData ad = (ApplicationData)ContentHelper.getPrimary((FormatContentHolder)ch);
url = ContentHelper.getDownloadURL(ch, ad, false).toString();
break;
}
else
{
validOutput=false;
message=message+"Secondary content not implemented.<br>\n";
}
}
if (url==null)
{
validOutput=false;
message=message+"Issue getting content for document " + number + ".<br>\n";
}
}
else
{
validOutput=false;
message=message+"Could not find document number " + number + ".<br>\n";
}
}
else if (source.equals("EPMDocument"))
{
QuerySpec qs = new QuerySpec(EPMDocumentMaster.class);
qs.appendWhere(new SearchCondition(EPMDocumentMaster.class,EPMDocumentMaster.NUMBER,SearchCondition.EQUAL, number));
QueryResult qr = PersistenceHelper.manager.find(qs);
if(qr.hasMoreElements())
{
EPMDocumentMaster docm = (EPMDocumentMaster) qr.nextElement();
QueryResult qrLatest = VersionControlHelper.service.allVersionsOf(docm);
while(qrLatest.hasMoreElements())
{
EPMDocument doc = (EPMDocument) qrLatest.nextElement();
if (version!= null)
{
if (!(doc.getVersionIdentifier().getValue().equals(version)))
continue;
}
ContentHolder ch = (ContentHolder)ContentHelper.service.getContents(doc);
if (type.equals("PRIMARY"))
{
ApplicationData ad = (ApplicationData)ContentHelper.getPrimary((FormatContentHolder)ch);
url = ContentHelper.getDownloadURL(ch, ad, false).toString();
break;
}
else
{
validOutput=false;
message=message+"Secondary content not implemented.<br>\n";
}
}
if (url==null)
{
validOutput=false;
message=message+"Issue getting content for cad document " + number + ".<br>\n";
}
}
else
{
validOutput=false;
message=message+"Could not find cad document number " + number + ".<br>\n";
}
}
if (validOutput)
{
response.sendRedirect(url);
}
else
{
response.setContentType("text/html");
out.println(message);
}
}
else
{
response.setContentType("text/html");
out.println(message);
}
%>
That is pretty remarkable piece of code, @avillanueva
I'd like to add that for Windchill 10.2 the link to this, let's call it ContentDownload.jsp, can be generated using the following java code
String theWTServerCodebase = ""; try { theWTServerCodebase = wt.util.WTProperties .getLocalProperties().getProperty("wt.server.codebase"); } catch (java.io.IOException e) { System.out.println("IOException:" + "\n" + e); } String dlUrl = theWTServerCodebase + "/app/netmarkets/jsp/<custom_folder_path>/ContentDownload.jsp?number=<custom_wtDoc_number>"; String displayName = "link name"; String link = "<a href=\"" + dlUrl + "\">" + displayName + "</a>"; System.out.println(link);