Scripting

Hi,

I’m trying to automatically give file paths names with a date according to a timestamp:

[color=#0000FF]date = timeStampString
results = event.source.parent.getComponent(‘Table’).data
spreadsheet = system.dataset.dataSetToExcel(1, [results])
filePath = “C:\Vat Report\Vat 1\” + date + “.xls”
system.file.writeFile(filePath, spreadsheet)[/color]

but I get the error

[color=#FF0080]Traceback (innermost last):
File “event:propertyChange”, line 12, in ?
IOError: The filename, directory name, or volume label syntax is incorrect
[/color]
What’s a better approach? :scratch: Thanks! :prayer:

The vast majority of programming languages give special meaning to backslashes in strings, as a way to specify various special characters. You’ll need to double up every backslash you need to really be a backslash in the string.
As a modern convenience, many languages’ file I/O libraries will accept unix-standard forward slashes as folder separators on all platforms, converting internally as needed. This is mostly true for Java.
So, two choices:filePath = "C:\\Vat Report\\Vat 1\\" + date + ".xls"Or:filePath = "C:/Vat Report/Vat 1/" + date + ".xls"

I tried:

[color=#0000FF]filePath = “C:\Vat Report\Vat 1\” + name + “.xls”[/color]

and

[color=#0040FF]filePath = “C:/Vat Report/Vat 1/” + name + “.xls”[/color]

and still get the error. :blush:

Just double checking… did you typo (or wordo…?)

you have ‘date’ defined…

in your last post you have ‘name’ not ‘date’…

Sorry about that. Yes it is defined as date and I copied and pasted the file path from the browser, and added the extra slashes as suggested. Is it because I’m adding a parameter to the file path?

“” + param + “”

date = timeStampString
results = event.source.parent.getComponent(‘Table’).data
spreadsheet = system.dataset.dataSetToExcel(1, [results])
filePath = “C:\Vat Report\Vat 1\” + date + “.xls”
system.file.writeFile(filePath, spreadsheet)

Thanks

Put in a “print filepath” just before you use it so you can see what you really have.

Thanks that worked. My problem was that I made a mistake on the date format expression. I changed it to the following and it works great. Thanks pturmel

dateFormat(toDate({Root Container.t_stamp}), “MMM d, yyyy”)

Should a URL be used instead as well? What machine ‘c:’ reference from the Gateway script vs the downloaded Designer (on a separate machine)?
Should these Gateway Scripts only be coded from the Gateway Host?