Hello everyone,
I'm having an issue with my script. I'm honestly just running test scripts but regardless if I'm putting in one that I thought would work or the actual script I want to be apart of the flow, I'm still running into the same error: "undefined is not a function." I've also tried the async version too and that also returned the exact same error. Can someone help me PLEASE because this is driving me insane!
"var fs = require("fs");
function jobArrived(s, flowElement, job) {
try {
s.log(1, "Script loaded successfully.");
var inputPath = job.getPath();
s.log(1, "Input path: " + inputPath);
var outputPath = inputPath + ".txt";
fs.writeFileSync(outputPath, "Hello from Classic Switch Script!");
job.sendToSingle(outputPath);
} catch (err) {
s.log(1, "Full error: " + JSON.stringify(err));
job.fail("Test script failed: " + err.message);
}
}"
Undefined is not a function
Re: Undefined is not a function
What you have been trying to do is write a NodeJS script as if it were a legacy script, but these two environments are quite different.
becomes
That is why you get the undefined error because the Switch class no longer has a method to log messages. It is either on the FlowElement or Job class that you log messages. When a Job instance is available it is better practice to use that one, so the line above is better like this:
Sending jobs also works differently. I am not going to explain that here. Please follow the scripting trail on the Learn section:
https://www.enfocus.com/en/learn/switch
Code: Select all
s.log(1, "Script loaded successfully");
Code: Select all
await flowElement.log(LogLevel.Info, "Script loaded successfully");
Code: Select all
await job.log(LogLevel.Info, "Script loaded successfully");
https://www.enfocus.com/en/learn/switch
Re: Undefined is not a function
Oh my gosh, you are a lifesaver thank you!! This was killing me! Also thank you for the link, I've been looking for something like this!!