cancel
Showing results for 
Search instead for 
Did you mean: 

Create folder rule from JavaScript API

pelican
Champ in-the-making
Champ in-the-making
Hello
I need to create the folder rule in JavaScript.
The rule is simple - at creation and change of contents run the js script.
How to make it?
4 REPLIES 4

scouil
Star Contributor
Star Contributor
Hi,

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

Then you should be good.

pelican
Champ in-the-making
Champ in-the-making
Thanks, but that's not what I need. I know how to do it in the GUI. I want to do it from another script.

scouil
Star Contributor
Star Contributor
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.

cheesywests
Champ in-the-making
Champ in-the-making
public CustomRuleCreator(ServiceRegistry serviceRegistry, Repository repository) {
   this.serviceRegistry = serviceRegistry;
   this.repository = repository;
   super.init(null);
}

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);
}

if it helps you
Thanks,
http://www.thecheesyanimation.com/Interior-Design-&-Rendering.html
Welcome to the new Hyland Connect. Get started or submit feedback.