cancel
Showing results for 
Search instead for 
Did you mean: 

Create / Edit Rule with Script?

e-manuel
Champ on-the-rise
Champ on-the-rise
Hi,

is it possible to create a script (Javascript/Webscript/…) to create Space-Rules or to edit them?

I have many many spaces (about 200 - 250) and i want to apply "notification-email-rules" to all these spaces.
I also want to edit other rules, there are already in some spaces (also rules, that sends emails to space-users on "any item").

How can i do this?
Example: In the Webclient, i would select "Create Rule", Condition="All Items", Action="Send an email to specified users", Value="Group_testgroup", Subject="New Document", Template="new_doc_template.ftl".

I already created all spaces and subspaces with a Javascript.

regards
Manuel

ps.: it's Alfresco 2.1
14 REPLIES 14

skontopo
Champ in-the-making
Champ in-the-making
Hi there!

Did you manage to find a solution to this problem?
Because I am also interested in this topic and I found your post while browsing the forum.

Thanks a lot in advance.

e-manuel
Champ on-the-rise
Champ on-the-rise
Hi,
unfortunately i haven't get any ideas how this is possible yet.

regards

lista
Star Contributor
Star Contributor
If those spaces have a hierarchy, then you can add a rule to the top one, and apply it to all the children too.
Presumably, your spaces are not related to each other?

Cheers,
Lista.

mcook
Champ in-the-making
Champ in-the-making
I have found a javascript api for creating rules; however, how to use it is currently beyond me.  Im working on it as we speak because I need this functionality to programmatically create rules on the fly for spaces that are created by scripts for documents that are scanned in.

http://wiki.alfresco.com/wiki/3.0_JavaScript_API_for_Rules_and_Actions

Matt

gabriele
Champ in-the-making
Champ in-the-making
I have the same problem and I also tried to follow the javascript API, though the "rules" host object doesn't seem to exists, like the Rule class itself.
Please let us know if you succeed.

I'm using Alfresco 3.2.

hyperation
Champ on-the-rise
Champ on-the-rise
Any luck?

benarrayx
Champ in-the-making
Champ in-the-making
It's also a requirement for me to create rules that apply to sub-folders I'm creating in code. I note that the Wiki page referred to above doesn't exist any more - can anyone else help out with any references on this?

AHA, Ben

unknown-user
Champ on-the-rise
Champ on-the-rise
Can someone clarify if this is possible through Web Scripts?
Thank you.

sanket
Champ on-the-rise
Champ on-the-rise
You can create rules programatically by using the following java code.
I don't know how to do it wid javascript.
For ex: If u want to create rule which converts the arriving document to pdf, u can do it programmatically as follows.

private void setupSpaceRuleConvToPDF(NodeRef data){
      
      Rule rule=new Rule();
      
       rule.setRuleType("inbound");
       rule.setTitle("Transform to PDF n copy to Data-PDF");
       rule.setDescription("Transform to PDF n copy to Data-PDF");
            rule.applyToChildren(false);
          // rule.setExecuteAsynchronously(true);
        System.out.println("Rule creation started…Part-II");
        CompositeAction compositeAction = getActionService().createCompositeAction();
        rule.setAction(compositeAction);
        ActionCondition actionCondition = getActionService().createActionCondition("no-condition");
        actionCondition.setParameterValues(new HashMap());
        compositeAction.addActionCondition(actionCondition);
        IHandler handler=null;
        Map repoActionParams = new HashMap();
        Map actionParams=new HashMap();
       
        NodeRef destination = new NodeRef(Repository.getStoreRef(),(String)getNodeService().getProperty(data, ContentModel.ASPECT_COPIEDFROM));
       
       
       
        actionParams.put("actionName", "transform");
        actionParams.put("transformer", "application/pdf");
        actionParams.put("destinationLocation",destination); // prntDestinationNodeRef
      actionParams.put("actionSummary", "Transform and copy content to a specific space");
      try {
          handler=(IHandler)Class.forName("org.alfresco.web.bean.actions.handlers.TransformHandler").newInstance();
      } catch (Exception e) {
         System.out.println("Class Generation Exception:"+e);
      }
      if(handler != null){
         handler.prepareForSave(actionParams, repoActionParams);
      }
       //System.out.println("B4 saving action");
      Action action = getActionService().createAction("transform");
      action.setParameterValues(repoActionParams);
        compositeAction.addAction(action);
        getRuleService().saveRule(data, rule);
   }