How to use timerFired() and sendTo() together properly?

Post Reply
reprokaiser
Newbie
Posts: 16
Joined: Mon Apr 04, 2011 3:56 pm

How to use timerFired() and sendTo() together properly?

Post by reprokaiser »

Dear All,



I'm struggling with a problem for some days, but no avail. Basically I want to check a folder for time to time, and sort the arrived files based on name and creation time. I think this is what timerFired() is for – the problem is that I can't send the files out. It's not really clear to me how to turn those files to 'jobs' to move.



function timerFired( s : Switch )

{

var theDir = new Dir( "/Storage/" );

var theFiles = theDir.entryList("*.pdf", Dir.Files, Dir.Name|Dir.Time );

var theNumOfFiles = theFiles.length;

if( theNumOfFiles != 0 )

{

for( x=0 ; x<=theNumOfFiles-1 ; x++ )

{

theFile = new File( "/Storage/" + theFiles[x] );

var theTempPath = s.createPathWithName( theFile.name );

s.copy( theFile.path, theTempPath );

s.sendToSingle( theTempPath, theFile.name );

}

}

}



It's clear that this sendToSingle isn't working here. Please help me: how to use it properly, or what to do instead of this? Any help appreciated.



Kind regards,



Peter
davidvd
Newbie
Posts: 9
Joined: Fri Feb 18, 2011 11:45 am

How to use timerFired() and sendTo() together properly?

Post by davidvd »

Peter,



You can't accomplish what you want using the "Assemble Job" tool? That has triggers that let you check every so many minutes or a number of minutes after the last file was found...



The approach you're taking does work though - you're correct in assuming that timerFired will do the trick. What you're struggling with is that Switch doesn't move single files around, it moves files around in the context of a "Job". When you use the jobArrived entry point, there is such a job that you can use; timerFired (by its nature) does not have that.



In your script, you need to use the:



createNewJob( origin : String ) : Job



function. This will create a new "job" object for you that you can then use to call sendToSingle on with the files you want to send out to the flow.



If you want all of those files to be connected (belong to the same job), call createNewJob only once and do multiple sendToSingle calls on it for all of your files. If you want each file to be sent along the flow as an independent job, call createNewJob repeatedly.



Hope this helps,

David.



reprokaiser wrote: Dear All,



I'm struggling with a problem for some days, but no avail. Basically I want to check a folder for time to time, and sort the arrived files based on name and creation time. I think this is what timerFired() is for – the problem is that I can't send the files out. It's not really clear to me how to turn those files to 'jobs' to move.



function timerFired( s : Switch )

{

var theDir = new Dir( "/Storage/" );

var theFiles = theDir.entryList("*.pdf", Dir.Files, Dir.Name|Dir.Time );

var theNumOfFiles = theFiles.length;

if( theNumOfFiles != 0 )

{

for( x=0 ; x
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

How to use timerFired() and sendTo() together properly?

Post by dkelly »

David has already pointed you in the right direction. I was working on a complete example for you.



The script can be simplified to:





function timerFired( s : Switch )

{

var theDir = new Dir( "/Storage/" );

var theFiles = theDir.entryList("*.pdf", Dir.Files, Dir.Name|Dir.Time );

var theNumOfFiles = theFiles.length;

if( theNumOfFiles != 0 ) {

for( x=0 ; x<=theNumOfFiles-1 ; x++ ) {

var j = s.createNewJob( "/Storage/" );

j.sendToSingle( theFiles[x] );

}

}

}





Sincerely,

Dwight Kelly

Apago, Inc.

dkelly@apago.com
Post Reply