Script for Content Rule in Alfresco Community 2.1.0

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

Script for Content Rule in Alfresco Community 2.1.0

Greetings.
As you might suspect, this Alfresco installation is 14 years old, during all this time it has been working perfectly and is currently still working.
The way to organize the contents is simple:
- There is a space called Clients within which are the spaces of each of the clients. The name of each client space is made up of a 6-digit code plus the client's name.
For example: 256500 Last Name1 Last Name2 , Customer first name.
- There is also a space called Check-In Registry where users deposit all client documents. These documents are named with a coding system that always begins with the Client Code (6 digits).
In this space (Input Record) there is a content rule that extracts the first 6 digits of the document name, does a search for customer spaces, and if there is a match in the 6-digit code between the document name and the name from the client space then copies (moves) the document to the client space and removes it from the Input Record.
If the space that matches is not located, send the document to a folder called Pending, which is located within the Entry Registration space.
It is an input rule that applies to all content and that executes a script whose code is the following:

var documento   = document.name;
var codigo = documento.substr(0,6);
var nombre = "Cliente "+codigo;
var pendientes = space.childByNamePath("Pendientes");
var carpetacliente = search.luceneSearch("+PATH:\"/app:company_home/cm:Clientes//*\" AND TYPE:\"cm:folder\" AND @cm\\:description:\""+nombre+"\"");

if (carpetacliente[0]!= null)
  {  
     if(carpetacliente[0].hasPermission("CreateChildren"))
      {
        var copy = document.move(carpetacliente[0]);
        if (copy != null)
      {
          document.name = documento;
         document.save();
       }
      }
     }
else
{
  var copy = document.move(pendientes);
   if (copy != null)                                   
     {
    document.name = documento;
    document.save();
     }
}

The problem is that we want to modify this script so that instead of extracting the first 6 digits of the document name and locating the client space, it does so for the first 4, leaving the last two digits for another type of procedure but already within the client's folder (space).
Obviously we have tried modifying the "code" variable by changing 6 to 4 but it does not work. I give an example:
- I have Space 256500 Last Name1 Last Name2, Customer Name
- I include in the Entry Registration the documents 256500T12022IP.pdf and 256501T12022HH.pdf (In the first the 6 digits coincide, but in the second only the first 5 and 4 should be enough)
The result is the same if I apply the script with the variable code 6 as if I apply the script with the variable 4. The document 256500T12022IP.pdf is moved to the client space and the document 256501T12022HH.pdf is moved to the pending folder.

I am not an expert in javascript, but I think there is not much more to modify in the code to be able to use only four digits.
Another thing I have observed is that if I perform a search for 6 digits, Alfresco does locate the client's space, but if I search for 4 digits, it does not. I don't know if there is any configuration parameter for the search, since I have tried to create a space using the template but instead of 6 digits I used 4 and it left me, so I don't really understand why the search must include the 6 digits.
I also don't know exactly if Alfresco has some type of Cache memory or similar.

can anyone help me about this?