Create folder rule from JavaScript API
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2015 03:14 AM
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?
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?
Labels:
- Labels:
-
Archive
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2015 06:46 AM
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.
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.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2015 07:47 AM
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.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2015 11:51 AM
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.
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.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2015 07:57 AM
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
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