In Alfresco content Modeling Article we have seen how to create custom content Model in Alfresco. In content types for relating multiple contents from same repository associations are used. In previous post about association I have explained the role of Association in Alfresco how they are using in alfresco and how can we create new association in custom content type.
Some of the times we have a requirement where we want to remove particular association from a single content or set of contents or may be from full repository.
So, in short we need to create script file according to our requirement, upload it under alfresco>Data Dictionary>Script and then associate that with rule and apply that rule to all contents on which association operation needs to be carried out.
We will be using node object’s apis to achieve this.
So let us take a look at the multiple scenarios
Delete specific association from content
for each (targetNode in document.assocs[“custom:myassociation”])
document.removeAssociation(targetNode, ” custom:myassociation “);
NOTE: It is always advisable to save content node after doing modification on node to ensure that transaction is committed properly. Sometimes you are likely to lose your changes if you do not use save method in the end of your script.
In this case “custom:myassociation” is the name of association which we want to remove from particular node or all set of contents.
For applying this script on set of contents create rule on top of folder under which all contents are lying and attach this script with rule and apply that rule to all existing contents. For more details on how to apply rule on existing contents refer this blog.