AnsweredAssumed Answered

syntax search.luceneSearch, like it?

Question asked by vlopez on Nov 14, 2009
Latest reply on Nov 17, 2009 by mikeh
Hi.

I write this post after reviewing, and reviewing the forums.

Alfresco community 2.9

I'm trying to create a script to move documents from one folder to another.
The folder structure is as follows:
–User Homes
  • Clientes
  • –000123Quijano Sanchez, Alonso
    –000877López Romero, Bernardo
    –001380Muñoz Quintero, Miguel
    ·
    ·
    –pendientes

The first six digits are the client code, the rest is free text.
The property description of each folder matches the client code.
   
The folder "pendientes" receive the documents named wrong, or when the client folder does not exist.

The names of the documents: 000877Contrato sales. Six-digit for client code and remainder free text.

By adding a document to the Clients folder this should be moved to the appropriate folder.

The script:


var documento   = document.name;
var nombre = documento.substr(0,6);
var pendientes = space.childByNamePath("pendientes");

var query = "/cm:User Homes/cm:Clientes/*";
query += ' +TYPE:"cm:folder"+@cm\:description:"\+ nombre + "\ ';

var carpetacliente = search.luceneSearch(query);
var ruta = space.childByNamePath(carpetacliente);

if (ruta != null && ruta.hasPermission("CreateChildren"))
{
   var copy = document.move(ruta);
   if (copy != null)
   {
      document.name = carpetacliente;
      document.save();
   }
}
else
{
  var copy = document.move(pendientes);
   if (copy != null)
     {
    document.name = carpetacliente;
    document.save();
     }
}

Function Search.luceneSearch does not work (probably because the sintax not good).
I've tested the node browser with different variants and returns me always the existence of the folder.

   
But when the query is added to the script I find that I return an error. Not see the folder.

The error message:

A system error happened during the operation: Failed to execute script 'workspace://SpacesStore/dc818d72-ce10-11de-a65d-43cb83d5086a': Failed to execute script 'workspace://SpacesStore/dc818d72-ce10-11de-a65d-43cb83d5086a': Wrapped java.lang.IllegalArgumentException: Local name cannot be null or empty. (AlfrescoScript#34)

Intentionally rename the document with the value returned by the search, and says (as shown in the error message), that name can not be an empty value ..
It seems that the search returns nothing.

What are the errors in creating the query?, Is it correct the way in which the variable "nombre" is included in the query…. if there are more mistakes … , are welcome (I'm not a developer and is normal to have committed more faults).

   
I thank in advance any help.

Outcomes