The easy way would be: - write your .js script - Drop it in /companyhome/Data Dictionary/Scripts Then - go to your folder - click "manage rules" - create new rule - Perform Action: execute script -> pick your script from the list - Configure the rest of the rule as you see fit
Oh OK I thought you wanted the rule to be an action written in js but didn't care how to add it.
Then any reason it needs to be in javascript? Java has a RuleService but it's not exposed to javascript. In JavaScript there are 3 solutions that I see: - Inject the RuleService as a javascript rule object. That's the one I'd recommend. - Call webscripts to create rule. But calling al Alfresco webscript when you are already in Alfresco isn't really nice on an architecture point of view. - Directly act at the file level since the rules are stored as any node. But it's not really future-proof and a bit messy so I wouldn't recommend it.
The createRule() method sets some of the simple rule properties such as title, description, etc in the parent class, calls setupRule() to set the more complex rule properties, then attaches the rule to the space. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 public void createRule(NodeRef targetSpace, JSONObject ruleDetail) throws JSONException { this.ruleJson = ruleJson; this.setTitle(this.ruleJson.getString("title")); this.setDescription(this.ruleJson.getString("description")); this.setType(this.ruleJson.getString("ruleType")); this.setRunInBackground(this.ruleJson.getBoolean("executeAsynchronously")); this.setApplyToSubSpaces(this.ruleJson.getBoolean("applyToChildren")); this.setRuleDisabled(this.ruleJson.getBoolean("disabled")); // create the new rule Rule rule = new Rule(); rule.setRuleType(this.getType()); // setup the rule this.setupRule(rule); // save the rule this.getRuleService().saveRule(targetSpace, rule); }