AnsweredAssumed Answered

script to seach in a specific space

Question asked by cperez on Apr 2, 2014
Latest reply on Apr 3, 2014 by cybermakoki
I'm makin a script to get all the objects in a specific space (called "Aprobados") where the created or last modified date is today. And I also want to get all metadata from the searchrd objects.

Can anyone help me please?

Let me explain you the process I need to execute

1) Search for all the pdf documents of a given space called "Aprobados" which have been modified "today".
2) I need to create a txt file with all the metadata of all of those modified pdf documents stored in this space that matched this search criteria.
3) Place the txt file in a given space so another process can get it by FTP

This is the code I have written, however I am not very sure of the search funcion, as I need to search in the "Aprobados" space but also inside its child nodes recursively.

Could you please take a look to my code and let me know if you think it is ok?

I will really appreciate it.

Cheers!!


// We create the folder to place the txt file
var subir = space.childByNamePath("Subir Facturas");
var recoger = subir.childByNamePath("Recoger");


// If there is already a txt file we must delete it
for each (var doc in recoger.children) {
   if (doc.mimetype == "text/plain");
      doc.remove();
}


// Get the path to the parent space where to look for the files
var revision = space.childByNamePath("Revisar");
var aprobados = revision.childByNamePath("Aprobadas");
var today = new Date();
var ano = today.getFullYear();
var buscarAno = aprobados.childByNamePath(ano);


// Now we firstly create the txt file
//String fecha = today.getDate() + "-" + today.getMonth() +1 + "-" + today.getFullYear();
file = recoger.createFile("metadatos_facturas.txt");

// We run the search for all the pdf files that have been modified today in the
// space of the current year
var docs = search.xpathSearch([cm:modified]=today,buscarAno);

// For each doc found matching the search clause we must write their metadata in the
// txt file - one row with metadata per file found

for each (docs) {

   if (docs!=null && docs.mimetype == "application/pdf")
   {
      workingcopy=file.checkout();
      workingcopy.content = "|"+docs.name+"|"+docs.start_date+"|"+docs.Private_Id+"|=";
      file = workingcopy.checkin();
   }
}

Outcomes