<?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 Re: How to change document type via javascript console in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/how-to-change-document-type-via-javascript-console/m-p/135630#M36448</link>
    <description>&lt;P&gt;Use the &lt;STRONG&gt;specializeType&lt;/STRONG&gt; method of the &lt;STRONG&gt;document&lt;/STRONG&gt; object:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://dev.alfresco.com/resource/docs/java/org/alfresco/repo/jscript/ScriptNode.html#specializeType-java.lang.String-" target="_blank" rel="nofollow noopener noreferrer"&gt;http://dev.alfresco.com/resource/docs/java/org/alfresco/repo/jscript/ScriptNode.html#specializeType-java.lang.String-&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 09 Mar 2022 14:30:30 GMT</pubDate>
    <dc:creator>angelborroy</dc:creator>
    <dc:date>2022-03-09T14:30:30Z</dc:date>
    <item>
      <title>How to change document type via javascript console</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-change-document-type-via-javascript-console/m-p/135629#M36447</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;I have created one document(test.txt) as &lt;STRONG&gt;cm:content&lt;/STRONG&gt; type via share UI.&lt;/P&gt;&lt;P&gt;I have changed its type to one of the custom type "&lt;STRONG&gt;dc:whitePaper&lt;/STRONG&gt;" using change type action on document details page.&lt;/P&gt;&lt;P&gt;Now, i want to convert the document to &lt;STRONG&gt;cm:content&lt;/STRONG&gt; type via javascript.&lt;/P&gt;&lt;P&gt;I have written below js code for this.&lt;/P&gt;&lt;PRE&gt;var query = '(TYPE:"dc:whitePaper")';
var queryDef = {query: query, store: "workspace://SpacesStore", language: "fts-alfresco", page: {maxItems: 200000, skipCount: 0}};
var results = search.query(queryDef);

logger.log(results.length);

for each(var document in results) {
	logger.log(document.properties.name);
	
	logger.log(document.type);
	
	logger.log(document.typeShort);

	
	if(document.type == "{http://www.democo.com/model/document/1.0}whitePaper")
	{
		document.typeShort = "cm:content";
		logger.log("after  "+document.typeShort);
		document.save();
		
		logger.log("saved");
	}
}&lt;/PRE&gt;&lt;P&gt;I didn't find any API for javascript that can change the content type of the document.&lt;/P&gt;&lt;P&gt;If javascript doesn't provide this API, can we do it via java based webscript?&lt;/P&gt;&lt;P&gt;Any other suggestions&amp;nbsp;please.&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 10:48:16 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-change-document-type-via-javascript-console/m-p/135629#M36447</guid>
      <dc:creator>hardik_thakkar</dc:creator>
      <dc:date>2022-03-09T10:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to change document type via javascript console</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-change-document-type-via-javascript-console/m-p/135630#M36448</link>
      <description>&lt;P&gt;Use the &lt;STRONG&gt;specializeType&lt;/STRONG&gt; method of the &lt;STRONG&gt;document&lt;/STRONG&gt; object:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://dev.alfresco.com/resource/docs/java/org/alfresco/repo/jscript/ScriptNode.html#specializeType-java.lang.String-" target="_blank" rel="nofollow noopener noreferrer"&gt;http://dev.alfresco.com/resource/docs/java/org/alfresco/repo/jscript/ScriptNode.html#specializeType-java.lang.String-&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 14:30:30 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-change-document-type-via-javascript-console/m-p/135630#M36448</guid>
      <dc:creator>angelborroy</dc:creator>
      <dc:date>2022-03-09T14:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to change document type via javascript console</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-change-document-type-via-javascript-console/m-p/135631#M36449</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/5487"&gt;@angelborroy&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried the below code, but its not allowing to change the type.&lt;/P&gt;&lt;PRE&gt;var node = search.findNode("workspace://SpacesStore/af0e5e5e-6ced-4c6c-92ce-1e45a2a37853");

logger.log(node.name);
logger.log(node.specializeType("{http://www.democo.com/model/document/1.0}whitePaper"));&lt;/PRE&gt;&lt;P&gt;I have created one document of cm:content type and now, i want to change it with custom one.&lt;/P&gt;&lt;P&gt;It gives output as false.&lt;BR /&gt;&lt;BR /&gt;If possible, can you please share any example for that?&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 16:33:09 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-change-document-type-via-javascript-console/m-p/135631#M36449</guid>
      <dc:creator>hardik_thakkar</dc:creator>
      <dc:date>2022-03-09T16:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to change document type via javascript console</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-change-document-type-via-javascript-console/m-p/135632#M36450</link>
      <description>&lt;P&gt;I would try this way instead &lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/14220"&gt;@hardik_thakkar&lt;/A&gt;&amp;nbsp;:&lt;/P&gt;
&lt;PRE&gt;var query = '(TYPE:"dc:whitePaper")';
var queryDef = {query: query, store: "workspace://SpacesStore", language: "fts-alfresco", page: {maxItems: 200000, skipCount: 0}};
var results = search.query(queryDef);

logger.log("Total count: "+ results.length);
for each(var document in results) {
	logger.log("Name: " + document.properties.name);
	
	logger.log("Type: " + document.type);
	
	if(document.type == "{http://www.democo.com/model/document/1.0}whitePaper")
	{
		var ctxt = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
		//make sure to use lower case bean id for nodeService or else you will get auth errors. &lt;BR /&gt;                var nodeService =  ctxt.getBean('nodeService', org.alfresco.service.cmr.repository.NodeService);
		var QName = Packages.org.alfresco.service.namespace.QName;

		var nodeTypeContent = QName.createQName("{http://www.alfresco.org/model/content/1.0}content");
		nodeService.setType(document.nodeRef, nodeTypeContent);
	}
}
&lt;/PRE&gt;

&lt;P&gt;You can also check bottom of this post:&amp;nbsp;&lt;A href="https://javaworld-abhinav.blogspot.com/2020/06/change-type-of-custom-content-types.html" target="_blank" rel="noopener nofollow noreferrer"&gt;https://javaworld-abhinav.blogspot.com/2020/06/change-type-of-custom-content-types.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 18:40:01 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-change-document-type-via-javascript-console/m-p/135632#M36450</guid>
      <dc:creator>abhinavmishra14</dc:creator>
      <dc:date>2022-03-10T18:40:01Z</dc:date>
    </item>
  </channel>
</rss>

