Update tags of folder content: error in script execution

cancel
Showing results for 
Search instead for 
Did you mean: 
redflow
Active Member II

Update tags of folder content: error in script execution

Hi all

I'm trying to define a script for a folder rule to update tags of folder content.

I have a script to set tags of all the document of a folder.

I'm trying to create one to update them when I change something in the folder's tags.

function update(pratica, node)
{
     for each (n in node.children)
     {
          if(n.isDocument)
          {
               var newCurrentTagArray = pratica.getTags();
               for each (tNodo in n.getTags())
               {
                    if (!newCurrentTagArray.includes(tNodo))
                         newCurrentTagArray.push(tNodo);
               }
               n.clearTags();
               n.addTags(newCurrentTagArray);
          }
          if(n.isContainer)
          {
               update(pratica, n);
          }
     }
}

var pratica = document;
//aggiorna i tag di tutti i documenti della pratica
update(pratica, pratica);

The problem is to check if in the tags of the document there is some tag that I want to maintain.....how could I user includes and push?

Here is the error I get:

ERROR [org.springframework.extensions.webscripts.AbstractRuntime] [http-apr-8080-exec-729] Exception from executeScript: 0414956638 Failed to execute script 'workspace://SpacesStore/f9cf4383-279b-4704-9374-8070b990400b': 0414956637 Java class "[Ljava.lang.String;" has no public instance field or method named "includes". (workspace://SpacesStore/f9cf4383-279b-4704-9374-8070b990400b#10) org.alfresco.scripts.ScriptException: 0414956638 Failed to execute script 'workspace://SpacesStore/f9cf4383-279b-4704-9374-8070b990400b': 0414956637 Java class "[Ljava.lang.String;" has no public instance field or method named "includes". (workspace://SpacesStore/f9cf4383-279b-4704-9374-8070b990400b#10) at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:261) at org.alfresco.repo.processor.ScriptServiceImpl.execute(ScriptServiceImpl.java:244) at org.2018-05-14 14:37:19,494 ERROR [org.springframework.extensions.webscripts.AbstractRuntime] [http-apr-8080-exec-729] Exception from executeScript: 0414956638 Failed to execute script 'workspace://SpacesStore/f9cf4383-279b-4704-9374-8070b990400b': 0414956637 Java class "[Ljava.lang.String;" has no public instance field or method named "includes". (workspace://SpacesStore/f9cf4383-279b-4704-9374-8070b990400b#10) org.alfresco.scripts.ScriptException: 0414956638 Failed to execute script 'workspace://SpacesStore/f9cf4383-279b-4704-9374-8070b990400b': 0414956637 Java class "[Ljava.lang.String;" has no public instance field or method named "includes". (workspace://SpacesStore/f9cf4383-279b-4704-9374-8070b990400b#10) at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:261) at org.alfresco.repo.processor.ScriptServiceImpl.execute(ScriptServiceImpl.java:244) at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:150) at sun.reflect.GeneratedMethodAccessor1854.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpointalfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:150) at sun.reflect.GeneratedMethodAccessor1854.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint

Thank you!

3 Replies
jpotts
Professional

Re: Update tags of folder content: error in script execution

The error is telling you exactly what the problem is: There is no method called "includes" on an array.

Try adding this function, then changing line 10 to call it instead:

function isInList(aList, listItem) {
    for (var i = 0; i < aList.length; i++) {
        if (aList[i] == listItem) {
            return true;
        }
    }
    return false;
}
redflow
Active Member II

Re: Update tags of folder content: error in script execution

Thank you Jeff,

do you think is there any workaround to do what I want to do?

Kindly regards

jpotts
Professional

Re: Update tags of folder content: error in script execution

Yes, I think you should be able to do that without a problem.

If you have not done so already you might install the Alfresco JavaScript Console. It makes iterating on this a lot easier.