AnsweredAssumed Answered

rules, javascript, move directories

Question asked by emelbye on Jan 22, 2013
Hi,

I've a proyect directory that include other folders… approved and Incomplete.
The images are in Ephesoft, came with metadata ant type ok.

I want to run a script thats verify if exists one or two types of documents (e.g type1 and type2). If exists, move to the folder 'approved', if not, to Incomplete.

Structure:

|- mycompany
|—- approved
|——– 000312312
|———- type1.pdf type2,pdf type3.pdf type4.pdf
|——– 312312312
|———- type1.pdf type2.pdf

|—- Incomplete
|——- 543523342
|——— type3.pdf tipo4.pdf

I apply a rule to mycompany folder.
When it create types of content:
In the script, i get the parent (the folder) and i verify that exists type1 and type2
If both of them not exists, i move them to Incomplete, else Aproved.

Here is the script.

var folder= document;

   var doc;

   var i, j;

   var esta;

   var tipos = new Array();

   var missing= new Array();

   var tiposDesc = new Array();



   tipos[0] = "tdk:Solicitud1";

   tipos[1] = "tdk:Solicitud2";

   tipos[2] = "tdk:Solicitud3";

   tipos[3] = "tdk:Solicitud4";

   tipos[4] = "tdk:Fotocopias";



   tiposDesc[0] = "Solicitud 1ra Hoja";

   tiposDesc[1] = "Solicitud 2da Hoja";

   tiposDesc[2] = "Solicitud 3ra Hoja";

   tiposDesc[3] = "Solicitud 4ta Hoja";

   tiposDesc[4] = "Fotocopia de DNI";



   for (j = 0; j < tipos.length; j++)

   {

      esta = false;

      for (i = 0; i < folder.children.length; i++)

      {

         doc = folder.children;

         if(doc.isSubType(tipos[j])){

            esta = true;

         }

      }

      if (!esta){

         missing[missing.length] = tipos[j];

      }

   }



   esta = false;

   for (i = 0; i < folder.children.length; i++)

   {

      doc = folder.children;

      if(doc.isSubType(tipos[4])){

         if (doc.properties["tdk:Fotocopias-TipoDNI"] == "SI"){

            esta = true;

         }   

      }

   }

   if (!esta){

      missing[missing.length] = tiposDesc[4];

   }



   var finalFolder;



   if (missing.length == 0){

      finalFolder= space.childByNamePath("Sitios/empresa/documentLibrary/Empresa/Legajos_Revisar");

         logger.log("All in");

   }

   else{

         finalFolder= space.childByNamePath("Sitios/empresa/documentLibrary/Empresa/Legajos_Incompletos");

      folder.properties.description = "Docs missing: " + missing;

         logger.log(missing);

   }

   folder.move(finalFolder);

Outcomes