cancel
Showing results for 
Search instead for 
Did you mean: 

Search in a folder with Javascript

patrickvanhoof
Confirmed Champ
Confirmed Champ

Hi,

I want to search for a file by it's name in a given folder via Javascript. I use following code:

nodes = search.luceneSearch("workspace://SpacesStore/61d28f13-24e0-434a-8b90-5ea54d2fafa2", "cm:name:" + nodeName);

But I get following error:

13:47:02,059 ERROR [org.springframework.extensions.webscripts.AbstractRuntime] [http-apr-8080-exec-58] Exception from executeScript - redirecting to status template error: 082235922 Failed to execute script 'workspace://SpacesStore/cba86b61-e294-406b-8c47-eaaa2b3854b7': 082235921 Failed to execute search: cm:name:Aerts_Dennis_94032021120_SAP4019
org.alfresco.scripts.ScriptException: 082235922 Failed to execute script 'workspace://SpacesStore/cba86b61-e294-406b-8c47-eaaa2b3854b7': 082235921 Failed to execute search: cm:name:Aerts_Dennis_94032021120_SAP4019
    at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:254)
    at org.alfresco.repo.processor.ScriptServiceImpl.execute(ScriptServiceImpl.java:237)
    at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:143)
    at sun.reflect.GeneratedMethodAccessor3606.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:34)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:164)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy361.executeScript(Unknown Source)
    at org.alfresco.repo.action.executer.ScriptActionExecuter.executeImpl(ScriptActionExecuter.java:164)
    at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:265)
    at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:838)
    at org.alfresco.repo.action.executer.CompositeActionExecuter.executeImpl(CompositeActionExecuter.java:66)
    at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:265)
    at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:838)
    at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:738)
    at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:572)
    at sun.reflect.GeneratedMethodAccessor3114.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:34)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:164)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy48.executeAction(Unknown Source)
    at org.alfresco.repo.rule.RuleServiceImpl.executeAction(RuleServiceImpl.java:1250)
    at org.alfresco.repo.rule.RuleServiceImpl.executeRule(RuleServiceImpl.java:1244)
    at org.alfresco.repo.rule.RuleServiceImpl.executePendingRule(RuleServiceImpl.java:1190)
    at org.alfresco.repo.rule.RuleServiceImpl.executePendingRulesImpl(RuleServiceImpl.java:1119)
    at org.alfresco.repo.rule.RuleServiceImpl.executePendingRules(RuleServiceImpl.java:1092)
    at org.alfresco.repo.rule.RuleTransactionListener.beforeCommit(RuleTransactionListener.java:57)
    at org.alfresco.repo.transaction.AlfrescoTransactionSupport$TransactionSynchronizationImpl.doBeforeCommit(AlfrescoTransactionSupport.java:737)
    at org.alfresco.repo.transaction.AlfrescoTransactionSupport$TransactionSynchronizationImpl.doBeforeCommit(AlfrescoTransactionSupport.java:717)
    at org.alfresco.repo.transaction.AlfrescoTransactionSupport$TransactionSynchronizationImpl.beforeCommit(AlfrescoTransactionSupport.java:683)
    at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:95)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:927)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:737)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
    at org.alfresco.util.transaction.SpringAwareUserTransaction.commit(SpringAwareUserTransaction.java:472)
    at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:472)
    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:495)
    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:553)
    at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:343)
    at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378)
    at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
    at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.alfresco.repo.webdav.auth.BaseSSOAuthenticationFilter.doFilter(BaseSSOAuthenticationFilter.java:137)
    at sun.reflect.GeneratedMethodAccessor1069.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.alfresco.repo.management.subsystems.ChainingSubsystemProxyFactory$1.invoke(ChainingSubsystemProxyFactory.java:112)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy323.doFilter(Unknown Source)
    at org.alfresco.repo.web.filter.beans.BeanProxyFilter.doFilter(BeanProxyFilter.java:82)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.alfresco.web.app.servlet.WebScriptSSOAuthenticationFilter.doFilter(WebScriptSSOAuthenticationFilter.java:114)
    at sun.reflect.GeneratedMethodAccessor1069.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.alfresco.repo.management.subsystems.ChainingSubsystemProxyFactory$1.invoke(ChainingSubsystemProxyFactory.java:112)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy323.doFilter(Unknown Source)
    at org.alfresco.repo.web.filter.beans.BeanProxyFilter.doFilter(BeanProxyFilter.java:82)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.alfresco.web.app.servlet.WebscriptCookieAuthenticationFilter.doFilter(WebscriptCookieAuthenticationFilter.java:61)
    at sun.reflect.GeneratedMethodAccessor1069.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.alfresco.repo.management.subsystems.ChainingSubsystemProxyFactory$1.invoke(ChainingSubsystemProxyFactory.java:125)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy323.doFilter(Unknown Source)
    at org.alfresco.repo.web.filter.beans.BeanProxyFilter.doFilter(BeanProxyFilter.java:82)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
Caused by: org.alfresco.error.AlfrescoRuntimeException: 082235921 Failed to execute search: cm:name:Aerts_Dennis_94032021120_SAP4019
    at org.alfresco.repo.jscript.Search.query(Search.java:827)
    at org.alfresco.repo.jscript.Search.query(Search.java:782)
    at org.alfresco.repo.jscript.Search.query(Search.java:741)
    at org.alfresco.repo.jscript.Search.luceneSearch(Search.java:329)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:155)
    at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
    at org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
    at org.mozilla.javascript.gen.c107._c1(workspace://SpacesStore/cba86b61-e294-406b-8c47-eaaa2b3854b7:12)
    at org.mozilla.javascript.gen.c107.call(workspace://SpacesStore/cba86b61-e294-406b-8c47-eaaa2b3854b7)
    at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:97)
    at org.mozilla.javascript.gen.c107._c2(workspace://SpacesStore/cba86b61-e294-406b-8c47-eaaa2b3854b7:33)
    at org.mozilla.javascript.gen.c107.call(workspace://SpacesStore/cba86b61-e294-406b-8c47-eaaa2b3854b7)
    at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:97)
    at org.mozilla.javascript.gen.c107._c3(workspace://SpacesStore/cba86b61-e294-406b-8c47-eaaa2b3854b7:51)
    at org.mozilla.javascript.gen.c107.call(workspace://SpacesStore/cba86b61-e294-406b-8c47-eaaa2b3854b7)
    at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:108)
    at org.mozilla.javascript.gen.c107._c0(workspace://SpacesStore/cba86b61-e294-406b-8c47-eaaa2b3854b7:67)
    at org.mozilla.javascript.gen.c107.call(workspace://SpacesStore/cba86b61-e294-406b-8c47-eaaa2b3854b7)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
    at org.mozilla.javascript.gen.c107.call(workspace://SpacesStore/cba86b61-e294-406b-8c47-eaaa2b3854b7)
    at org.mozilla.javascript.gen.c107.exec(workspace://SpacesStore/cba86b61-e294-406b-8c47-eaaa2b3854b7)
    at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:502)
    at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:250)
    ... 121 more
Caused by: org.alfresco.error.AlfrescoRuntimeException: 082235920 No solr query support for store workspace://SpacesStore/8802c714-55e1-4b03-aa93-aa01d1a71a23
    at org.alfresco.repo.search.impl.solr.SolrQueryHTTPClient.executeQuery(SolrQueryHTTPClient.java:224)
    at org.alfresco.repo.search.impl.solr.SolrQueryLanguage.executeQuery(SolrQueryLanguage.java:49)
    at org.alfresco.repo.search.impl.solr.SolrSearchService.query(SolrSearchService.java:348)
    at org.alfresco.repo.search.SearcherComponent.query(SearcherComponent.java:78)
    at sun.reflect.GeneratedMethodAccessor2827.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.alfresco.repo.management.subsystems.SubsystemProxyFactory$1.invoke(SubsystemProxyFactory.java:72)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy15.query(Unknown Source)
    at org.alfresco.repo.search.impl.SearchServiceSubSystemDelegator.query(SearchServiceSubSystemDelegator.java:126)
    at sun.reflect.GeneratedMethodAccessor2827.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:80)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:164)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy15.query(Unknown Source)
    at org.alfresco.repo.jscript.Search.query(Search.java:807)
    ... 148 more

What am I doing wrong?

Thanks.

1 ACCEPTED ANSWER

One desperate last ditch workaround you can try is forcing those values to be regular native strings.

if(String(nodeName) === String(nodes[i].name))

View answer in original post

11 REPLIES 11

openpj
Elite Collaborator
Elite Collaborator

Try the following code:

nodes = search.luceneSearch("@cm\\:name:\"" + nodeName+ "\" AND PARENT:\"workspace://SpacesStore/61d28f13-24e0-434a-8b90-5ea54d2fafa2\"");

or you can get the node of the folder and then get all the children, using the database, for example in this way:

var folderNode = search.luceneSearch("TYPE:\"cm:folder\" AND @cm\\:name:\"<YOUR_FOLDER_NAME>\"")[0];

Another choise for finding the folderNode could be getting it using the discovery of the tree:

var folderNode = companyhome.childByNamePath("/YOUR/FOLDER/PATH");

Then you can get all the children:

var folderNodeChildrenXPathQuery = "*[@cm:name='"+messageFrom+"']";

var nodes = folderNode.childrenByXPath(folderNodeChildrenXPathQuery);

Hope this helps.

afaust
Legendary Innovator
Legendary Innovator

I strongly recommend to avoid using search.luceneSearch() (and put it on a mental "ban list"). This operation uses a technical query language that has no support for the performance-related improvements around transactional metadata queries. Unfortunately it can't be easily removed from the public API since too many people rely on it and it is still being recommended (as in this thread) even though it should be obsolete.

(BTW: search.xpathSearch should also be avoided in favor of search.selectNodes - childrenByXPath on the other hand is perfectly fine)

The alternative to luceneSearch would be search.query:

var nodes = search.query({
   language: 'fts-alfresco', // this is the primary FTS language in Alfresco with best support (only other contender is cmis-alfresco)
   query : 'PARENT:"workspace://SpacesStore/61d28f13-24e0-434a-8b90-5ea54d2fafa2" AND =cm:name:"' + nodeName + '"'
});

Only "fts-alfresco" and "cmis-alfresco" are optimised to use the database for simple queries, like PARENT and exact name match conditions. search.selectNodes and childrenByXPath also use the database but in a less optimal way (conditions are evaluated in Java code and not during the database select).

Hi Axel,

I changed the query line to

query: 'PARENT:"workspace://SpacesStore/d54db46e-9539-45e9-8b49-55ed1ac1968a" AND "cm:name:" + nodeName'

because I think the syntax was not correct.

The script is running but I do not get results, although I know that in that parent there is a folder with that name.

Is this syntax ok for getting the search results:

for each (node in nodes.children) {

     log = "Folder " + node.name + " gevonden\n";
     logFile.content += log;
}

Thanks,

Patrick

afaust
Legendary Innovator
Legendary Innovator

The syntax was actually correct for finding exact matches and also supporting database queries. But your variant would also work, but you need to be aware of any whitespaces in nodeName which can break the query. That's why I put it in paranthesis.

The for-each loop should be fine to iterate, although I prefer the for-loop with an explicit iteration index.

Like this?

for (i = 0; i < nodes.length; i++) {
     log = "Folder " + nodes[i].name + " gevonden\n";
     logFile.content += log;
}

Yes, like this. The main issue with the for-each loop is that it is a deprecated extension

One last thing. I have following loop:

for (i = 0; i < nodes.length; i++) {

     log = "[" + nodeName + "]=\n" + "[" + nodes[i].name + "]?\n";
     logFile.content += log;
               
     if (nodes[i].name == nodeName) {

          log = "Folder " + nodes[i].name + " gevonden\n";
          logFile.content += log;

          found = true;
          break;
     }
}

The first log gives me:

[Aerts_Dennis_94032021120_SAP4019]=

[Aerts_Dennis_94032021120_SAP4019]?

So they seem to be equal, but  the following if statement results in false... Also when I use the === operator.

afaust
Legendary Innovator
Legendary Innovator

The operator === can only be used for string objects if you are reasonably sure that both strings are native JavaScript strings. The scripting integration in Alfresco exposes strings from Java as well, which can by definition not be structurally identical with JavaScript strings.

The == should always work when comparing semantically identical strings. Why this does not yield true in your case I am not sure. Is there some kind of invisible control character in one of the strings?

As far as I know there is no control character in one of the strings. I tried different things but I can't get the if statement to return true...