Quantcast
Channel: PTC Community: Message List - Windchill
Viewing all articles
Browse latest Browse all 8876

Re: How java code to create WTDocument from template in Project Content

$
0
0

Hi,

 

Try below code to create WTDocument using template.

  1. 1. First we have to write this class TemplateHelper.java

 

package ext.ptc;

 

import java.io.InputStream;

 

import com.ptc.windchill.enterprise.doc.server.DocumentUtility;

import com.ptc.windchill.enterprise.templates.TemplatesFactory;

 

import wt.admin.AdminDomainRef;

import wt.content.ApplicationData;

import wt.content.ContentServerHelper;

import wt.doc.DepartmentList;

import wt.doc.DocumentType;

import wt.doc.WTDocument;

import wt.enterprise.EnterpriseHelper;

import wt.enterprise.SequenceGenerator;

import wt.enterprise.TemplatesUtility;

import wt.inf.container.WTContainer;

import wt.inf.container.WTContainerHelper;

import wt.query.QuerySpec;

import wt.query.SearchCondition;

import wt.util.WTProperties;

 

public class TemplateHelper {

 

  /**

* return the WTDocument object basis the template name

* @param templateName

* @param orgName

* @throws Exception

*/

public static WTDocument getDocumentTemplate(String templateName, String orgName) throws Exception

{

QuerySpec qs = new QuerySpec(WTDocument.class);

SearchCondition templateNameSC = new SearchCondition(WTDocument.class,WTDocument.NAME,

SearchCondition.EQUAL,templateName);

qs.appendWhere(templateNameSC, new int[]{0,1});

 

WTContainer container = WTContainerHelper.service.getByPath("/wt.inf.container.OrgContainer="+orgName).getReferencedContainer();

System.out.println("Cont Name in getDocTemp ==>"+container.getName());

wt.fc.QueryResult qrTemplates = EnterpriseHelper.service.getTemplates(container,

  qs, null, true, true, true);

 

if(qrTemplates.hasMoreElements())

return ((WTDocument)qrTemplates.nextElement());

else

return null;

}

 

}

 

 

2. Later we have to give these inputs pertaining to specific document subtype wherever it is getting created:

In my scenario, I was adhering document template of subtype ‘Commercial proposal document’ for organization ‘PTC’ where ‘Commercial Proposal Document’ Is the name of the Template.

 

 

  1. cmpDOC.setDomainRef(doc.getDomainRef());

WTDocument docTemplate = TemplateHelper.getDocumentTemplate("Commercial Proposal Template", "PTC");

System.out.println("Document Template Name : - "+docTemplate.getName());

doc=(WTDocument) VersionControlHelper.service.getLatestIteration(doc, true);

System.out.println("childDoc  Name : - "+doc.getName());

PersistenceHelper.manager.save(cmpDOC);

wt.content.ContentHelper.service.copyContent((wt.content.ContentHolder)docTemplate, (wt.content.ContentHolder)cmpDOC);

 

Thanks,

Kaushik


Viewing all articles
Browse latest Browse all 8876

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>