cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to delete Content Rules using Javascript API ?

msevestre
Champ in-the-making
Champ in-the-making
Hello

I will migrate my data to the latest version of Alfresco and at the same time, I want to delete all the Content Rules that exists in my current data tree as they will become useless.

I am able to change rights using javascripts without problems (via calls to SetPermission(), etc..), but I have not found any solution to delete a content rule. Could you please help me ?

Thank you for your help
Matthew
11 REPLIES 11

msevestre
Champ in-the-making
Champ in-the-making
Hello

no success until now… I give up and will keep my useless content rules for now.

Thanks for your help and to have taken time trying to help me !

Matt

kaynezhang
World-Class Innovator
World-Class Innovator
In fact you can still use javascript api to delete rules ,in alfresco rules are saved as nodes .rules applied to a node A is saved under A with child associations named {http://www.alfresco.org/model/rule/1.0}ruleFolder.
So you can delete rules applied to a node by using ScriptNode api to delete sub nodes,this is not a direct way.
following is a profile of an example
if you want to delete all rules,follow step 1.2.16.17
if you want to remove some rules,follow all steps except 16.17

1.var ruleFolder = mynode.childAssocs["{http://www.alfresco.org/model/rule/1.0}ruleFolder"][0];//mynode is the node whose rules  you want to delete
2.mynode.removeNode(ruleFolder);
3.rules = ruleFolder.childAssocs["{http://www.alfresco.org/model/rule/1.0}ruleFolder"];
4.for(i=0;i<rules.length;i++)
5.{
6.   var obj = rules;
7.   var reg = new  RegExp("^rules.*");
8.   if(reg.exec(obj.properties.name)){//node name matches ^rules.*  regular expression is rule node
9.      // add your code here to idenfify rule you want to delete
10.      if(***){
11.         rules.removeNode(obj);
12.      }
13.   }
14.}
15.rules.save();
16.mynode.removeAspect("{http://www.alfresco.org/model/rule/1.0}rules");//remove mynode's rules aspect;
17.mynode.save();

You 'd better run a test before you use these code to make sure they do the right thing.