Hi Team,
I have created one document(test.txt) as cm:content type via share UI.
I have changed its type to one of the custom type "dc:whitePaper" using change type action on document details page.
Now, i want to convert the document to cm:content type via javascript.
I have written below js code for this.
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"); } }
I didn't find any API for javascript that can change the content type of the document.
If javascript doesn't provide this API, can we do it via java based webscript?
Any other suggestions please.
Thanks in advance!
Solved! Go to Solution.
I would try this way instead @hardik_thakkar :
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.
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); } }
You can also check bottom of this post: https://javaworld-abhinav.blogspot.com/2020/06/change-type-of-custom-content-types.html
Use the specializeType method of the document object:
Hi @angelborroy
I have tried the below code, but its not allowing to change the type.
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"));
I have created one document of cm:content type and now, i want to change it with custom one.
It gives output as false.
If possible, can you please share any example for that?
Thanks in advance!
I would try this way instead @hardik_thakkar :
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.
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); } }
You can also check bottom of this post: https://javaworld-abhinav.blogspot.com/2020/06/change-type-of-custom-content-types.html
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.