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!
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;
}
Thank you Jeff,
do you think is there any workaround to do what I want to do?
Kindly regards
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.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.