Page 1 of 1

Syntax Error

Posted: Wed Apr 11, 2018 9:20 pm
by mclarke
I'm trying to teach myself Javascript in order to better use the Scripting module. I have a question about a syntax error in my first script.
I'd like to set the value of a property in a flow element with a simple script. I came up with the following:

var fileStat = new FileStatistics(job.getPath());
var checkPath = fileStat.getString("[Metadata.Text:Path="/field-list/field[2]/value",Dataset="NYCM-Sort-Submit-All",Model="XML"]");
if checkPath === "FIRST CLASS" {
return "C:/JSON_files/NYCM-260.json";
}
return "C:/JSON_files/NYCM-261.json"

The value is from an XML submit point dataset. I'm sure I'm way off base, but would appreciate it for someone to explain what I did wrong.

Thank you.

Re: Syntax Error

Posted: Wed Apr 11, 2018 10:25 pm
by cstevens
FileStatistics are normally used for getting properties of a PDL file like number of pages, trim size etc. I think you want the embedded data set

Code: Select all

var dataset = job.getDataset("NYCM-Sort-Submit-All");
Then you can use evalToString to get the value you want out of the XML:

Code: Select all

var checkPath = dataset.evalToString("/field-list/field[2]/value", null);

Re: Syntax Error

Posted: Thu Apr 12, 2018 6:57 pm
by mclarke
I will make the change, thank you.

Enfocus doesn't really make interpreting the help file easy for beginners.

Re: Syntax Error

Posted: Tue Mar 26, 2019 10:09 pm
by rgpepper
mclarke wrote: Thu Apr 12, 2018 6:57 pm I will make the change, thank you.

Enfocus doesn't really make interpreting the help file easy for beginners.
Right??! It doesn't translate well, there's a "layer"missing I'd say.

Re: Syntax Error

Posted: Wed Mar 27, 2019 2:00 pm
by mclarke
Thanks to posters here and some dedicated Internet research on my own, I'm getting better at the simple scripting. But, this is one area that Enfocus could really help out new users. The flow element and apps from the store will only get you so far, if you need to move into more advanced flows.

I wouldn't even mind paying for good, Switch-focused online training in Javascript and script development.

Re: Syntax Error

Posted: Wed Mar 27, 2019 2:06 pm
by jan_suhr
mclarke wrote: Wed Mar 27, 2019 2:00 pm I wouldn't even mind paying for good, Switch-focused online training in Javascript and script development.
Dwight Kelly have seminars now and then on Scripting Switch.

viewtopic.php?f=13&t=2239