AnsweredAssumed Answered

Not possible to change document type multiple times?

Question asked by mathias.lin on Nov 12, 2015
I try to <strong>set the document type of a node</strong> via JavaScript API in Alfresco 5.0.d as follows.

It <strong>works the first time, it does not work any subsequent time</strong> I try it again - even when assigning the same document type, and also without having changed any document properties or the status of the document.

Is it only possible to specialize the type in Alfresco once? (The side-effects if changing a document type are clear, and of course need to be taken care of, but that's a different story.)

My javascript code - I executed it this way for demonstration purposes in the JS console:


    var node = space.childByNamePath("MyDocument.txt");
   
    var success = node.specializeType("{my.new.model}sop");
    logger.log("Success: " + success);
    logger.log("NodeType: " + node.type);
   
    success = node.specializeType("{my.new.model}sop");
    logger.log("Success: " + success);
    logger.log("NodeType: " + node.type);


Output:


    Success: true
    NodeType: {my.new.model}sop
    Success: false
    NodeType: {my.new.model}sop


The MyDocument.txt is a simple txt document that I had just created via Share and was originally of type cm:content.

<strong>*** Update: ***</strong>

No idea why this topic gets automatically locked, so I need to provide an answer in here.

Found the problem myself: node.specializeType() is only for setting the type to a <strong>sub-type</strong>, not any other type, so it needs to be inheriting from the original type.

Outcomes