What am I missing? I'm attempting to stash a piece of text in the JobState to be retrieved later by a configurator.
// 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 )
{
var jobName = job.getNameProper();
job.log(1, jobName);
if (jobName.includes ("PORTFL")) {
job.setJobState("PORTFL");
}
if (jobName.includes ("PORTFD")) {
job.setJobState("PORTFD");
}
if (jobName.includes ("LANDFL")) {
job.setJobState("LANDFL");
}
if (jobName.includes ("LANDFD")) {
job.setJobState("LANDFD");
}
job.sendToSingle( job.getPath());
}
I get an error at whatever line number the second "if" is on, so presumably my first if statement is incorrect, though I don't get any syntax errors when saving the script
Java "Includes" Not Working
Re: Java "Includes" Not Working
Take my comments with a grain of salt because I don't have access to Switch Scripter any longer.
1) You have an extra space before you invoke the .includes method
should be
2) MDN says that String.prototype.includes() was introduced for ECMAScript 2015. Last I heard SwitchScriper uses a modified ES4, so this may not be available https://developer.mozilla.org/en-US/doc ... g/includes
You can see what is available in the Scripter string here https://www.enfocus.com/manuals/Develop ... tring.html
3) I think the way to do this in Switch would be to use indexOf on a particular pattern or substring like so:
4) I would use a private data key for storing this instead of jobstate because it provides more context about what is stored there and its less likely to get overwritten by something else (including a folder with JS set).
1) You have an extra space before you invoke the .includes method
Code: Select all
if (jobName.includes ("PORTFL")) {
job.setJobState("PORTFL");
}
Code: Select all
if (jobName.includes("PORTFL")) {
job.setJobState("PORTFL");
}
You can see what is available in the Scripter string here https://www.enfocus.com/manuals/Develop ... tring.html
3) I think the way to do this in Switch would be to use indexOf on a particular pattern or substring like so:
Code: Select all
function jobArrived( s : Switch, job : Job )
{
var jobName = job.getNameProper();
job.log(1, jobName);
if (jobName.indexOf("PORTFL") !== -1) {
job.setJobState("PORTFL");
}
/* etc */
job.sendToSingle( job.getPath());
}
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.
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.
Re: Java "Includes" Not Working
Thanks! Turns out I did have to use "IndexOf", and I'm golden!