Very Simple String output via Switch Javascript-Expression

Post Reply
CSHoltey
Newbie
Posts: 2
Joined: Thu May 28, 2020 6:06 pm

Very Simple String output via Switch Javascript-Expression

Post by CSHoltey »

Hello,

i´am trying to have a string-Output via the Javascript-Expression in the "Submit hierarchy"-Element. I use the script in the "Adjusted by (rule ...)".

So, when i use the following Script, the Script Expression give no Response:

$Fillvar = "MOUNTAIN";
$Fillvar;


Is there a mistake in the Script?
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: Very Simple String output via Switch Javascript-Expression

Post by Padawan »

When you are using a script expression in the submit hierarchy, then you don't have to return a name like you do in the regular editors. Instead, the script expression is called for each file which is scanned. The job object links to the file which is being scanned. The script expression should return true or false whether the job should be added to the flow or not.

This might seem a bit counter intuitive compared to the way the regular editors work, but it does make it a lot more powerful. You could for example create a script expression which filters based on file size instead of name.
CSHoltey
Newbie
Posts: 2
Joined: Thu May 28, 2020 6:06 pm

Re: Very Simple String output via Switch Javascript-Expression

Post by CSHoltey »

Hey, thank you for answering

i understand but one way to use the "Submit hierarchy" is to select a "special named Subfolder" to bring only this Folder into the following Flow.

I tried to the select one special Folder in a static way and It worked well. I used the menu-selection "Folder-Pattern" to ask for the special Subfolder ( "MOUNTAIN") . In this case i give the value "MOUNTAIN*" and Switch selected only this Folder instead of using the whole Folderstructer around it.
It works fine.

- but when i try to make it dynamic and use a variable instead of a static value in the menu-selection "Adjusted by (rule ...)" to select this special Folder – switch get no response in form of a string value.
I can´t understand why because I think the Javascipt Expression has normally the possibility to response the value of a variable to the switch-Flow. In the case of "rename a file" it runs successfully to work with the value of a variable in Switch like i wrote it in my Opening-Thread.
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: Very Simple String output via Switch Javascript-Expression

Post by Padawan »

Hierarchies are a complicated subject, even without combining it with scripting. If you haven't done so already, it might be a good idea to check the enfocus e-learnings on hierarchies.
CSHoltey wrote: Mon Jun 15, 2020 3:52 pm i understand but one way to use the "Submit hierarchy" is to select a "special named Subfolder" to bring only this Folder into the following Flow.
If you have a folder called "MOUNTAIN", then you can setup a rule to move the content of the "MOUNTAIN" folder into the Switch flow. Not the "MOUNTAIN" folder itself. This is one of the things which is not obvious on submit hierarchy on first sight.
CSHoltey wrote: Mon Jun 15, 2020 3:52 pm - but when i try to make it dynamic and use a variable instead of a static value in the menu-selection "Adjusted by (rule ...)" to select this special Folder – switch get no response in form of a string value.
From the "Submit hierarchy" part of the Switch 2019 fall reference guide:
Note: If you're using a script expression, remember that the script expression should return a boolean value (true or false), instead of a string matching the folder name. For example, you could create a script expression to filter out all folders smaller than 1 MB. If the checked folder < 1 MB (= matches), the result of the script is "true" and the folder is filtered out.
So it is really important to have a script expression which returns a boolean instead of a string.

If you have a working submit hierarchy filter with "MOUNTAIN*" as folder pattern for the folder name, then you should get the same result using the following script expression:

Code: Select all

var isTheRightFolder = false
var folderName = job.getNameProper();
if (folderName == "MOUNTAIN") {
	isTheRightFolder =  true;
}
s.log(1, "Folder name \"" + folderName + "\" is the right folder: " + isTheRightFolder);
isTheRightFolder;
This will also report in the messages on which folders are checked and what the result of the check is. This can give more insight of how these script expressions work.
Post Reply