Routing jobs to external hotfolders with "s.copy"

Post Reply
KaesDS
Newbie
Posts: 12
Joined: Thu Sep 22, 2016 10:33 am

Routing jobs to external hotfolders with "s.copy"

Post by KaesDS »

Hello guys,

i created a script/configurator that routes jobs to various external hotfolders with matching names (matching metadata with foldername).
That works quite well so far. Unfortunately, if you use "s.copy", the job prefix will be preserved. Is there a way to remove the job prefix within the script without using "sendto"? We currently have more than 100 hotfolders in use and want a solution without having to integrate all folders in switch.

I would be grateful for any suggestion. :geek:

Code: Select all

// Is invoked each time a new job arrives in one of the input folders for the flow element.
// The newly arrived job is passed as the second parameter.
function jobArrived(s: Switch, job: Job)

{

  //Einstellungen des Konfigurators
  var folderPath = s.getPropertyValue("rip_path", job) + "\\";
  var errorPath = s.getPropertyValue("error_path", job) + "\\";
  var linoPath = s.getPropertyValue("linoPath", job) + "\\";
  var checkName = s.getPropertyValue("checkName", job);
  var dataset = s.getPropertyValue("dataset", job);
  //Jobname für Ausgabe
  var name = job.getName();
  //Pfad zum Hotfolder
  var folder = new Dir(folderPath);
  //Suchname
  var shortJobName = job.getNameProper().match(/^[^ ]+/);
  //Wenn/Dann Jobname/Name aus Metadaten
  if (checkName == "Name aus Metadaten")

  {
	  // Metadaten Infos auslesen (Kunde, Menge)
	  customer = job.getVariableAsString('[Metadata.Text:Path="/order/customer",Dataset="' + dataset + '",Model="XML"]');
	  amount = job.getVariableAsNumber('[Metadata.Integer:Path="/order/products/product/amount",Dataset="' + dataset + '",Model="XML"]');
	  shortJobName = customer + "_" + amount;

  } else

  {
    shortJobName = shortJobName;
  }
  
  switch (shortJobName) {
		case "geers_10":
			shortJobName = "geers_hno_10";
			break;
		case "geers_15":
			shortJobName = "geers_hno_15";
			break;
		case "geers_20":
			shortJobName = "geers_hno_20";
			break;
		default: shortJobName = shortJobName;	
	}

  //Alle Hotfolder mit dem Dateinamen abgleichen
  var entries = folder.entryList(shortJobName + "*", Dir.Dirs | Dir.NoDotAndDotDot, Dir.Unsorted);  
  
  // Wenn mehr als "0" Suchtreffer, dann ...
  if (entries.length > 0)

  {
	 //Wenn genau "1" Suchtreffer 
    if (entries.length == 1)

    {
      s.copy(job.getPath(), folderPath + entries[0] + "/" + name);
      job.log(1, "Das PDF '" + name + " (" + shortJobName + ")" + "' wurde dem Hotfolder '" + entries[0] + "' zugeordnet.");

    } else

    {
      //Error wenn mehr als "1" Suchtreffer
      s.copy(job.getPath(), errorPath + name);
      job.log(3, "Das PDF '" + name + " (" + shortJobName + ")" + "' konnte keinem Hotfolder zugeordnet werden, da es mehr als einen passenden Ordner gab.");

    }

  } else

  {
    //Error wenn kein Suchtreffer
    s.copy(job.getPath(), errorPath + name);
    job.log(3, "Das PDF '" + name + " (" + shortJobName + ")" + "' konnte keinem Hotfolder zugeordnet werden! Sie finden es im Ordner: " + errorPath);

  }

  job.sendToNull(job.getPath());
}
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Routing jobs to external hotfolders with "s.copy"

Post by jan_suhr »

The manual says:
Note: This function should be used only to copy files to a temporary location; use the Job.sendTo() functions for moving files to outgoing connections.

Can't you use the Set Hierarchy Path and variables to construct the folder path to where you copy your files?
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
KaesDS
Newbie
Posts: 12
Joined: Thu Sep 22, 2016 10:33 am

Re: Routing jobs to external hotfolders with "s.copy"

Post by KaesDS »

Thank you, Jan. Why didn't I think of that myself? :? Your solution works great!
Post Reply