cancel
Showing results for 
Search instead for 
Did you mean: 

JavaScript for showing/manipulating rules

lercherl
Champ on-the-rise
Champ on-the-rise
I want to automate a few checks concerning rules (e.g. check whether rules are disabled, apply to subfolders etc.). It seems there is no JavaScript API for showing/manipulating rules. Starting from hints found in this discussion:
https://forums.alfresco.com/forum/developer-discussions/other-apis/there-way-delete-content-rules-us...
I could do most of what I need to do using the general node API. Starting from the rule folder and recursively traversing its children I can find all the rules, its conditions, actions and parameters.

But there is one exception: If a rule executes a script I cannot get the UUID or some other unique identifier of the script. Here's an example: I list all of the nodes' properties and find one like this:


{http://www.alfresco.org/model/system/1.0}node-dbid: 239416
{http://www.alfresco.org/model/action/1.0}parameterName: script-ref
{http://www.alfresco.org/model/action/1.0}parameterValue: Node Type: {http://www.alfresco.org/model/content/1.0}content, Node Aspects: [{http://www.alfresco.org/model/content/1.0}indexControl, {http://www.alfresco.org/model/content/1.0}versionable, {http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/system/1.0}localized]


The value of the parameter named "script-ref" is not a reference to a script, but rather a list of its aspects. This is very strange, since querying the database directly gives the node UUID as expected:


select q.local_name, p.string_value from alf_node_properties p, alf_qname q  where p.qname_id = q.id and p.node_id = 239416;
   local_name   |                         string_value                        
—————-+————————————————————–
parameterValue | workspace://SpacesStore/f1a5113c-8a95-497d-aac1-378f41e9b547
parameterName  | script-ref


Is this a bug or a feature?
2 REPLIES 2

lercherl
Champ on-the-rise
Champ on-the-rise
I can answer my own question. The property "parameterValue" is not a script uuid, url or whatever, but rather the script node itself. I didn't know that a node property can be a node - you always learn something new. Using a node in a string context results in the strange list of aspects.

The following JavaScript snippet does what I want:


for (prop in node.properties ) {
    if ( prop == '{http://www.alfresco.org/model/action/1.0}parameterValue'
    && node.properties["{http://www.alfresco.org/model/action/1.0}parameterName"] == 'script-ref' ) {
    var scriptNodeName =  node.properties[prop].properties.name );
       // [… do something with scriptNodeName]
    } else {
       var nodePropertyValue = node.properties[prop] );
      //  [… do something with nodePropertyValue]
    }
}

msroth
Champ in-the-making
Champ in-the-making

I have a similar need, any chance you could share all of your code?  Much appreciated.