<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic how to get documents template from library using api in windchill in Windchill Customization</title>
    <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/how-to-get-documents-template-from-library-using-api-in/m-p/627024#M4573</link>
    <description>&lt;P&gt;how to get documents template from library using api code through a workflow , i have a code which convert template to document automatically but only one input , i need to give the ibrary container as input to convert all templates into document&lt;/P&gt;</description>
    <pubDate>Fri, 15 Mar 2024 13:21:00 GMT</pubDate>
    <dc:creator>Ramakaliappan</dc:creator>
    <dc:date>2024-03-15T13:21:00Z</dc:date>
    <item>
      <title>how to get documents template from library using api in windchill</title>
      <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/how-to-get-documents-template-from-library-using-api-in/m-p/627024#M4573</link>
      <description>&lt;P&gt;how to get documents template from library using api code through a workflow , i have a code which convert template to document automatically but only one input , i need to give the ibrary container as input to convert all templates into document&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 13:21:00 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Windchill-Customization/how-to-get-documents-template-from-library-using-api-in/m-p/627024#M4573</guid>
      <dc:creator>Ramakaliappan</dc:creator>
      <dc:date>2024-03-15T13:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to get documents template from library using api in windchill</title>
      <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/how-to-get-documents-template-from-library-using-api-in/m-p/653801#M4574</link>
      <description>&lt;P&gt;Hi&lt;SPAN class="UserName lia-user-name lia-user-rank-Regular-Member lia-component-message-view-widget-author-username"&gt; &lt;A id="link_9" class="lia-link-navigation lia-page-link lia-user-name-link" style="color: #000000;" href="https://community.ptc.com/t5/user/viewprofilepage/user-id/300241" target="_self"&gt;&lt;SPAN class=""&gt;Ramakaliappan,&lt;/SPAN&gt;&lt;/A&gt; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="UserName lia-user-name lia-user-rank-Regular-Member lia-component-message-view-widget-author-username"&gt;&lt;SPAN class=""&gt;looks like method&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;wt.enterprise.EnterpriseHelper.service.getTemplates&lt;/P&gt;
&lt;P&gt;does the trick.&amp;nbsp; It is however not part of the JavaDoc,and therefore perhaps a little bit unsupported ;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BR,&lt;/P&gt;
&lt;P&gt;Joachim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 11:27:19 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Windchill-Customization/how-to-get-documents-template-from-library-using-api-in/m-p/653801#M4574</guid>
      <dc:creator>JoachimLoos</dc:creator>
      <dc:date>2020-03-11T11:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to get documents template from library using api in windchill</title>
      <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/how-to-get-documents-template-from-library-using-api-in/m-p/653807#M4575</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thanks Joachim&amp;nbsp; , but i written a different code , it helped me.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 11:59:41 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Windchill-Customization/how-to-get-documents-template-from-library-using-api-in/m-p/653807#M4575</guid>
      <dc:creator>Ramakaliappan</dc:creator>
      <dc:date>2020-03-11T11:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to get documents template from library using api in windchill</title>
      <link>https://www.ptcusercommunity.com/t5/Windchill-Customization/how-to-get-documents-template-from-library-using-api-in/m-p/653809#M4576</link>
      <description>&lt;P&gt;package ext.test;&lt;BR /&gt;import java.util.ArrayList;&lt;BR /&gt;import wt.content.ContentHelper;&lt;BR /&gt;import wt.content.ContentHolder;&lt;BR /&gt;import wt.doc.WTDocument;&lt;BR /&gt;import wt.enterprise.TemplatesUtility;&lt;BR /&gt;import wt.fc.PersistenceHelper;&lt;BR /&gt;import wt.fc.ReferenceFactory;&lt;BR /&gt;import wt.folder.FolderHelper;&lt;BR /&gt;import wt.folder.FolderingInfo;&lt;BR /&gt;import wt.inf.container.WTContainer;&lt;BR /&gt;import wt.inf.container.WTContainerRef;&lt;BR /&gt;import wt.util.WTException;&lt;BR /&gt;import wt.vc.VersionControlHelper;&lt;BR /&gt;public class WTDocumentHelper {&lt;BR /&gt;public static WTDocument getDocumentTemplate(String&lt;BR /&gt;paramDocTemplateContainerRef)&lt;/P&gt;
&lt;P&gt;paramDocTemplateName,&lt;/P&gt;
&lt;P&gt;WTContainerRef&lt;/P&gt;
&lt;P&gt;{&lt;BR /&gt;WTDocument docTemplate = null;&lt;BR /&gt;ReferenceFactory refFact = new wt.fc.ReferenceFactory();&lt;BR /&gt;try {&lt;BR /&gt;ArrayList asd = wt.doc.WTDocumentHelper.service.getTemplates(paramDocTemplateContainerRef);&lt;BR /&gt;for(int i = 0; i &amp;lt; asd.size(); i++){&lt;BR /&gt;String[] tpl = (String[]) asd.get(i);&lt;/P&gt;
&lt;P&gt;if (tpl[1].equals(paramDocTemplateName)){&lt;BR /&gt;docTemplate = (WTDocument) refFact.getReference(tpl[4]).getObject();&lt;BR /&gt;break;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;docTemplate=(WTDocument) VersionControlHelper.service.getLatestIteration(docTemplate, true);&lt;BR /&gt;if (docTemplate==null)&lt;BR /&gt;throw new WTException("Not found WTDocument Template :" + paramDocTemplateName);&lt;BR /&gt;} catch (WTException e) {&lt;BR /&gt;e.printStackTrace();&lt;BR /&gt;}&lt;BR /&gt;return docTemplate;&lt;BR /&gt;}&lt;BR /&gt;public static WTDocument createDocumentFromTemplate(String paramDocName,String&lt;BR /&gt;paramDocTemplateName, WTContainer paramDocContainer) throws WTException {&lt;BR /&gt;WTDocument doc = null;&lt;BR /&gt;WTContainerRef contRef = WTContainerRef.newWTContainerRef(paramDocContainer);&lt;BR /&gt;try {&lt;BR /&gt;WTDocument docTemplate = getDocumentTemplate(paramDocTemplateName,contRef);&lt;BR /&gt;doc = WTDocument.newWTDocument();&lt;BR /&gt;doc.setName(paramDocName);&lt;BR /&gt;doc.setTypeDefinitionReference(docTemplate.getTypeDefinitionReference());&lt;BR /&gt;doc.setContainerReference(contRef);&lt;BR /&gt;doc.setDomainRef(paramDocContainer.getDefaultDomainReference());&lt;BR /&gt;doc.setFormat(docTemplate.getFormat());&lt;BR /&gt;PersistenceHelper.manager.save(doc);&lt;/P&gt;
&lt;P&gt;//Copy primary content file from Template&lt;BR /&gt;ContentHelper.service.copyContent((ContentHolder)docTemplate,&lt;BR /&gt;(ContentHolder) doc);&lt;BR /&gt;//Rename primary content file&lt;BR /&gt;doc = (WTDocument)TemplatesUtility.setFilename((WTDocument)doc);&lt;BR /&gt;} catch (Exception e) {&lt;BR /&gt;e.printStackTrace();&lt;BR /&gt;}&lt;BR /&gt;return doc;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;*while coping and pasting ,check for the alignment.&lt;/P&gt;
&lt;P&gt;create a new work flow after that&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Refer Sample expression code for reference.&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;System.out.println("*******START************");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;wt.part.WTPart part = (wt.part.WTPart)primaryBusinessObject;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(part, null, null, null);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;obj.load("Choose_library");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;String attrValue = (String) obj.get("Choose_library");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;System.out.println("The selected library is "+attrValue);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;String a = attrValue;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;System.out.println("The selected library is "+a);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;if(a.equals("Library4")) { ref =&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;wt.inf.container.WTContainerHelper.service.getByPath("wt.inf.container.OrgContainer=WeaponX/wt.inf.library.WTLibrary=Lib&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;rary4"); }&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;else if(a.equals("Library3")) { ref =&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;wt.inf.container.WTContainerHelper.service.getByPath("wt.inf.container.OrgContainer=WeaponX/wt.inf.library.WTLibrary=Lib&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;rary3"); }&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;else if(a.equals("Library2")) { ref =&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;wt.inf.container.WTContainerHelper.service.getByPath("wt.inf.container.OrgContainer=WeaponX/wt.inf.library.WTLibrary=Lib&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;rary2"); }&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;else if(a.equals("Library1")) { ref =&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;wt.inf.container.WTContainerHelper.service.getByPath("wt.inf.container.OrgContainer=WeaponX/wt.inf.library.WTLibrary=Lib&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;rary1"); }&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;else { System.out.println("PLEASE CONTACT ADMIN"); }&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;java.util.ArrayList asd = wt.doc.WTDocumentHelper.service.getTemplates(ref);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;for(int i = 0; i &amp;lt; asd.size(); i++)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;String[] template = (String[])asd.get(i);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;System.out.println("The Selected template is " +template[1]);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;wt.part.WTPartMaster master = (wt.part.WTPartMaster) part.getMaster();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;System.out.println("***** Name -&amp;gt;"+ master.getName());&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;wt.part.WTPart latest = (wt.part.WTPart)wt.vc.VersionControlHelper.service.allVersionsOf(master).nextElement();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;String versionLatest = wt.vc.VersionControlHelper.getVersionIdentifier(latest).getValue();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;System.out.println("******** Identity -&amp;gt; "+ latest.getIdentity());&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;System.out.println("******** Latest Version -&amp;gt; "+ versionLatest);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;System.out.println("******** Latest Iteration -&amp;gt; "+ latest.getIterationDisplayIdentifier());&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;System.out.println("******** State of latest version of latest iteration -&amp;gt; "+latest.getState());&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;if (versionLatest.equals("A") == true){&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;System.out.println("********Automatic Document Creation Workflow has Started************** ");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;wt.inf.container.WTContainer container = ref.getContainer();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;String paramDocTemplateName = template[1];&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;String paramDocName = paramDocTemplateName;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;wt.doc.WTDocument docFromTemplate = null;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;try{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;docFromTemplate= ext.test.WTDocumentHelper.createDocumentFromTemplate(paramDocName, paramDocTemplateName,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;container);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;}catch (Exception e) {&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;e.printStackTrace();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;}&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;System.out.println("************Automatic Document Creation Workflow has Ended********** ");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;System.out.println("********DESCRIBE LINK ATTACHING**********");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;wt.part.WTPartDescribeLink wl=wt.part.WTPartDescribeLink.newWTPartDescribeLink(part, docFromTemplate);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;wt.fc.PersistenceServerHelper.manager.insert(wl);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;System.out.println("**********DESCRIBE LINK ATTACHED******");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;}&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;else&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;System.out.println("************THIS IS A REVISED VERSION**************");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;}&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;}&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;System.out.println("***********END******************* ");&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;*while coping and pasting ,check for the alignment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 12:07:40 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/Windchill-Customization/how-to-get-documents-template-from-library-using-api-in/m-p/653809#M4576</guid>
      <dc:creator>Ramakaliappan</dc:creator>
      <dc:date>2020-03-11T12:07:40Z</dc:date>
    </item>
  </channel>
</rss>

