Let say that we have an aspect and we want to remove that aspect from some nodes that have certain ids
Just showing the nodes
logger.debug("INIT rm aspect"); var idList = [ "1788", "1789", "1790" ]; for(i = 0; i < idList.length; i++){ var query = "ASPECT:\"ca:customAspect\" AND @ca\\:docId:\""+ idList[i] +"\""; logger.debug("QUERY:" + query); var results = search.luceneSearch(query); if (results.length >= 1) { var node = results[0]; var name = node.properties["cm:name"]; logger.debug("FILENAME:" + name + " NODEREF:" + node.nodeRef); } }
We recommend first just print the name of the document that will be changed as show in the previews code.
In general is a good idea if you use javascript console to write changes in the repository, to do an version of the script that doesn’t change the nodes but highlight the node upon the change will be made to do a check that you are not doing something wrong.
And then after checking that the list hasn’t any undesired node you canĀ proceedĀ to eliminate the aspect from that list of nodes.
Actually deleting the aspect
logger.debug("INIT rm aspect"); var idList = [ "1788", "1789", "1790" ]; for(i = 0; i < idList.length; i++){ var query = "ASPECT:\"ca:customAspect\" AND @ca\\:docId:\""+ idList[i] +"\""; logger.debug("QUERY:" + query); var results = search.luceneSearch(query); if (results.length >= 1) { var node = results[0]; var name = node.properties["cm:name"]; logger.debug("FILENAME:" + name + " NODEREF:" + node.nodeRef); node.removeAspect("ca:customAspect"); node.save(); } }
Javascript is a really quick and powerful tool, and for the same reason it is really easy to make regrettable mistakes with it.