Job Creation in webhookTriggered() - File Does Not Exists...

Post Reply
patgilmour
Newbie
Posts: 13
Joined: Mon Jul 06, 2015 10:56 pm

Job Creation in webhookTriggered() - File Does Not Exists...

Post by patgilmour »

Hi,

I'm creating a new job within the webhookTriggered() function. I've tried using the standard example from the docs:

Code: Select all

//create new job  
    var job = s.createNewJob();
    var f = new File(job.getPath());  
    f.open(File.WriteOnly);
    f.writeLine("Sample line.");
    f.close();

    //single outgoing connection only
    job.sendToSingle(job.getPath());
This works but creates a file called '_XXXXX_dummyFileForNewJob.dat'

What I need to do is take a path/filename and send that to single instead. Something like:

Code: Select all

//create new job  
    var job = s.createNewJob();
    
    var logPath = job.createPathWithName("logFile.txt");
    
    var f = new File( logPath );  
    f.open(File.WriteOnly);
    f.writeLine("Sample line.");
    f.close();

    //single outgoing connection only
    job.sendToSingle( logPath );
This "sort of" works. It creates a correctly named file at path that I can send to single. But I also see this in the Messages Log...

File does not exists: /Users/work/Library/Application Support/Enfocus/SwitchScripter/temp/EnvironmentClass/85/_0077G_dummyFileForNewJob.dat

So I try adding this at the bottom of the code:

Code: Select all

job.sendToNull( job.getPath() );
But the "File does not exists" (need to fix the grammar there too!) message persists.

My Question:

Within a function that has no "job" to use (timerFired(), webhookTriggered()), how do I create a file at a path and send it to single without getting a "File does not exists" message?

Thanks for any insights into this.

-Pat
User avatar
gabrielp
Advanced member
Posts: 645
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: Job Creation in webhookTriggered() - File Does Not Exists...

Post by gabrielp »

Honestly Pat, what you have in the second example looks correct to me. It's what I've done in scripts before: https://github.com/open-automation/swit ... js#L42-L51

The only thing I'd add is set the "createFolder" argument:

Code: Select all

var logPath = job.createPathWithName("logFile.txt", false);
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore

Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
patgilmour
Newbie
Posts: 13
Joined: Mon Jul 06, 2015 10:56 pm

Re: Job Creation in webhookTriggered() - File Does Not Exists...

Post by patgilmour »

Gabriel - thanks for the reply! I did try adding the 'false' parameter as a second option, but it made no difference to the message in the Log.

I guess this is just another bug (and typo) in the Scripting module.
Post Reply