2

I have developed a Suitlet script that, in particular, loads an .xml file for further processing using the file.load method with an absolute path. I want to use a relative path, but when I do so, it won't work.

Basically, I'm providing the file.load method with the absolute path of an .xml file.

I expect the same behavior with a relative path provided instead, but it throws an error.

Both my Suitlet and .xml are in the same folder next to each other.

Forks fine:

var xmlTemplateFile = file.load({ id: 'SuiteScripts/printXml/template.xml' });

Doesn't work:

var xmlTemplateFile = file.load({ id: 'template.xml' });

Error message:

{"type":"error.SuiteScriptError","name":"RCRD_DSNT_EXIST","message":"That record does not exist. path: template.xml

I expect file.load, provided with a relative path, to load my .xml file seamlessly.

ProgrammerPer
  • 1,125
  • 1
  • 11
  • 26
  • Try using this `./template.xml` – Satish Kumar May 27 '19 at 08:08
  • Thanks for quick answer! I have tried all variations ./template.xml, /template.xml, but it didn't work – Vlad Shepshuk May 27 '19 at 08:12
  • Are you sure that your code is inside `SuiteScript/printXml/`? I mean both xml and your code file are inside `SuiteScript/printXml/`? – Satish Kumar May 27 '19 at 08:15
  • Yes, both files are in SuiteScripts/printXml/ – Vlad Shepshuk May 27 '19 at 08:18
  • Could you give a short explanation of why you need a relative path so we could possibly find another solution? – Adam May 28 '19 at 01:28
  • @Adam, Thanks for your reply! I was totaly fine with absolute path before I realized that my working directory is put inside SuiteBundles/Bundle ${unique_#} directory after deployment into production. Since that, the absolute path does not lead to my .xml file which makes the whole Suitlet useless. – Vlad Shepshuk May 28 '19 at 12:17
  • 1
    @ShepshukVlad see [here](https://github.com/michoelchaikin/netsuite-mapreduce-util/blob/master/SDF/FileCabinet/SuiteScripts/MOS%20Map%20Reduce%20Utility/mos_mapReduceUtil.ts#L78) for a workaround – michoel May 30 '19 at 05:08
  • @michoel, nice workaround! Actually I have done similar thing about path being built as SuiteBundles/Bundle #, where bundle # is taken via runtime module. This works for any files inside a Bundle # directory though, while your solution provides more flexible way of handling the files. Thanks! – Vlad Shepshuk May 30 '19 at 13:40

2 Answers2

3

file.load() does not accept paths relative to the current file. Not much you can do about it other than submit a feature request to NetSuite.

erictgrubaugh
  • 8,519
  • 1
  • 20
  • 28
  • 2
    It's worth noting here that the Help Center documentation is very poor in a lot of areas -- this being one of them. The parameter is described as being a relative path though it's actually an absolute path. – Adam May 28 '19 at 01:26
0

This should work with ./template.xml. e.g. var xmlTemplateFile = file.load({ id: './template.xml' });

Eric Levy
  • 11
  • 2